package com.koocloud.electroplatemanage.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Validator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.base.CaseFormat;

import com.koocloud.electroplatemanage.auth.mapper.IUserDao;
import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.mapper.*;
import com.koocloud.electroplatemanage.pojo.*;
import com.koocloud.electroplatemanage.pojo.mainpojo.OrderResource;
import com.koocloud.electroplatemanage.pojo.mainpojo.Route;
import com.koocloud.electroplatemanage.pojo.mainpojo.WIP;
import com.koocloud.electroplatemanage.pojo.mainpojo.WorkOrder;
import com.koocloud.electroplatemanage.service.IncomePartJudgeService;
import com.koocloud.electroplatemanage.utils.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import static com.koocloud.electroplatemanage.constant.IncomePartJudgeSqlFieldConstant.*;
import static com.koocloud.electroplatemanage.constant.MainWIPRouteConstant.BASICINFORMATIONSOURCE;
import static com.koocloud.electroplatemanage.constant.MainWIPRouteConstant.INCOMEPARTENTRY;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @program: electroplatemanage
 * @description: 来料接收与判定服务层实现类
 * @author: zww
 * @create: 2020-10-08 13:29
 */
@Service
@Transactional(rollbackFor=Exception.class)
public class IncomePartJudgeServiceImpl implements IncomePartJudgeService {
    @Resource
    private IncomePartJudgeMapper incomePartJudgeMapper;
    @Resource
    private IncomePartJudgeFieldMapper incomePartJudgeFieldMapper;
    @Resource
    private DrawNoMapper drawNoMapper;
    @Resource
    private ParameterTableMapper parameterTableMapper;
    @Resource
    private IncomePartUnitMapper incomePartUnitMapper;
    @Resource
    private TypeWorkMapper typeWorkMapper;
    @Resource
    private IUserDao iUserDao;
    @Resource
    private WorkTimeMapper workTimeMapper;
    @Resource
    private AssignJobMapper assignJobMapper;
    @Resource
    private MainProductionMapper mainProductionMapper;
    Lock lock=new ReentrantLock();
    /**
     *@Description:工艺卡片打印查询
     *@Param: [page, limit, beginTime, endTime, idOrName]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/25
     */
    @Override
    public ResponseTemplate selectProcessCardPrinting(String page, String limit, String beginTime, String endTime, String idOrName) {
        //校验分页参数是否为纯数字 并且page和limit不都等于0
        if (Validator.isNumber(page) && Validator.isNumber(limit) && !("0".equals(page) && "0".equals(limit))) {
            try {
                //根据map中的key获取对应列的数值
                if (StringUtils.isEmpty(beginTime)){
                    beginTime= "1970-01-01";//HexUtil.getCurrentDate();
                }
                if (StringUtils.isEmpty(endTime)){
                    endTime= "2100-12-30";//HexUtil.getCurrentDate();
                }
                //开始分页
                PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
                List<LinkedHashMap> secondList = incomePartJudgeMapper.selectProcessCardPrinting(beginTime ,endTime, idOrName);
                for(int i = 0; i<secondList.size();i++) {

                    Iterator it = secondList.get(i).entrySet().iterator();
                    LinkedHashMap linkedHashMap = new LinkedHashMap();
                    while (it.hasNext()) {

                        Map.Entry entry = (Map.Entry) it.next();
                        //驼峰字段名称
                        linkedHashMap.put(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, (String) entry.getKey()),entry.getValue());
                    }
                    secondList.set(i,linkedHashMap);

                }
                //构造分页实体
                PageInfo<LinkedHashMap> info = new PageInfo<>(secondList);
                if (info.getTotal() > 0) {
                    //查询到数据
                    return ResponseTemplate.builder().code(0).message("查询成功").count((long) info.getTotal()).data(info.getList()).build();
                } else {
                    //没有查询到数据
                    return ResponseTemplate.builder().code(1).message("没有查到对应数据").count(0l).build();
                }

            } catch (Exception e) {
                //事务手动回滚
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                //遇到异常，返回异常原因
                e.printStackTrace();
                return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
            }
        } else {
            return ResponseTemplate.builder().code(1).message("分页参数错误").count(0l).build();
        }
    }
    /**
     *@Description:通过pk查询一条记录
     *@Param: [pk]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/08
     */
    @Override
    public ResponseTemplate selectByPk(String id) {


            try {
                    String sql = getIncomePartJudgeEnableField();
                    if (!StringUtils.isEmpty(sql)) {

                        //新建来料接收与判定实体
                        IncomePartJudgeVo incomePartJudgeVo = null;
                        incomePartJudgeVo = incomePartJudgeMapper.selectByPk(id, sql);
                        //判断查表操作是否成功
                        if (null != incomePartJudgeVo) {
                            //查表成功返回数据
                            return ResponseTemplate.builder().code(0).message("查询成功").count(1l).data(incomePartJudgeVo).build();
                        } else {
                            //查表失败返回提示
                            return ResponseTemplate.builder().code(1).message("没有此数据").count(0l).build();
                        }
                    }
                    else {
                        return ResponseTemplate.builder().code(1).message("来料接收与判定字段均未启用").count(0l).build();
                    }


            } catch (Exception e) {
                //事务手动回滚
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                //遇到异常，返回异常原因
                e.printStackTrace();
                return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
            }
    }

    /**
     *@Description:查询所有记录 分页
     *@Param: [page, limit]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/08
     */
    @Override
    public ResponseTemplate selectAllData(String page, String limit,String beginTime,String endTime,String idOrName) {
        //校验分页参数是否为纯数字 并且page和limit不都等于0
        if (Validator.isNumber(page) && Validator.isNumber(limit) && !("0".equals(page) && "0".equals(limit))) {
            try {
                //来料接收与判定字段启用字段
                String sql = getIncomePartJudgeEnableField();
                System.out.println("===========>sql:" + sql + "========>");
                if (!StringUtils.isEmpty(sql)) {


                    //将返回的数据封装为map集合
                    Map<String, Object> map = new HashMap<>();
                    //1.获取第一个数组
                    //查询来料接收与判定表字段表启用字段的相关信息(根据orderid排序)
                    List<IncomePartJudgeFieldVo> incomePartJudgeFieldVos = incomePartJudgeFieldMapper.selectEnableFieldInfo1();
                  /*  for (Iterator<IncomePartJudgeFieldVo> iterator = incomePartJudgeFieldVos.iterator(); iterator.hasNext();) {
                        IncomePartJudgeFieldVo incomePartJudgeFieldVo = iterator.next();
                        if ("delete_flag".equals(incomePartJudgeFieldVo.getEnfieldName())) {
                            iterator.remove();
                        }
                    }*/
                    //驼峰字段信息
                    List<IncomePartJudgeFieldVo> incomePartJudgeFieldHumpVos = incomePartJudgeFieldVos;

                    if (incomePartJudgeFieldHumpVos.size() > 0) {
                        for (IncomePartJudgeFieldVo incomePartJudgeFieldVo : incomePartJudgeFieldHumpVos) {

                                incomePartJudgeFieldVo.setEnfieldName(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, incomePartJudgeFieldVo.getEnfieldName()));

                        }

                    }
                    //1.存放第一个数组
                    map.put("firstList", incomePartJudgeFieldHumpVos);


                        System.out.println("拼接的sql：" + sql);
                        log("拼接的sql:" + sql);
                        PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
                        //根据map中的key获取对应列的数值
                        if (StringUtils.isEmpty(beginTime)){
                            beginTime= "1970-01-01";//HexUtil.getCurrentDate();
                        }
                        if (StringUtils.isEmpty(endTime)){
                            endTime= "2100-12-30";//HexUtil.getCurrentDate();
                        }
                        List<LinkedHashMap> secondList = new ArrayList<>();
                        //判断模糊查询是否为状态查询 启用为 1 禁用为 0
                        if (!StringUtils.isEmpty(idOrName)){
                            //启用
                            if (UNFINISHED.equals(idOrName)){
                                idOrName = TWO;
                                String state = BASICINFORMATIONSOURCE;
                                secondList = incomePartJudgeMapper.selectByDeleteFlag(sql,beginTime ,endTime, idOrName, state);
                            //模糊查询
                            } else {
                                secondList = incomePartJudgeMapper.selectAllData(sql,beginTime ,endTime, idOrName);
                            }
                        }else {
                            //全局查询
                            secondList = incomePartJudgeMapper.selectAllData(sql,beginTime ,endTime, idOrName);
                        }

                        if (secondList.size()>0) {

                            for (int i = 0; i < secondList.size(); i++) {
                                //获取每条数据的序id
                                String id = secondList.get(i).get("id").toString();
                                //获取每条数据的型号
                                String modelNumber = String.valueOf(secondList.get(i).get(MODELNUMBER));
                                //获取每条数据的零件名称
                                String partName = String.valueOf(secondList.get(i).get(PARTNAME));
                                //获取每条数据的图号
                                String drawNoCode = String.valueOf(secondList.get(i).get(DRAW_NO_CODE));
                                //获取每条数据的工号
                                String typeWorkCode = String.valueOf(secondList.get(i).get(TYPE_WORK_CODE));
                                //获取每条数据的完成数量
                                String quantityCompleted = String.valueOf(secondList.get(i).get(QUANTITY_COMPLETED));
                                //获取每条数据的含税单价
                                String unitPriceIncludeTax = null;
                                //获取每条数据的工时
                                String workTime = null;
                                //获取每条数据的操作人
                                StringBuffer operator = new StringBuffer();
                                Iterator it = secondList.get(i).entrySet().iterator();
                                LinkedHashMap linkedHashMap = new LinkedHashMap();
                                while (it.hasNext()) {

                                    Map.Entry entry = (Map.Entry) it.next();
                                    if(DRAW_NO_CODE.equals((String) entry.getKey())) {
                                      if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                          DrawNoVo drawNoVo = drawNoMapper.selectByPk((String) entry.getValue());
                                          if(!StringUtils.isEmpty(drawNoVo)) {
                                              //设置图号code+name
                                              entry.setValue(drawNoVo.getDrawNoCode()+"-"+drawNoVo.getName());
                                          }
                                      }
                                    }
                                    //图号+工种
                                    if(DRAW_ADD_TYPEWORK.equals((String) entry.getKey())) {
                                        if(StringUtils.isEmpty((String) entry.getValue())|| " ".equals((String) entry.getValue())) {
                                            if((!StringUtils.isEmpty(drawNoCode)&&!" ".equals(drawNoCode) && (!StringUtils.isEmpty(typeWorkCode)&&!" ".equals(typeWorkCode)))){
                                                DrawNoVo drawNoVo = drawNoMapper.selectByPk(drawNoCode);
                                                TypeWorkVo typeWorkVo = typeWorkMapper.selectByPk(typeWorkCode);
                                                if(!StringUtils.isEmpty(drawNoVo) &&!StringUtils.isEmpty(typeWorkVo)) {
                                                    //图号+工种
                                                    entry.setValue(drawNoVo.getName()+typeWorkVo.getName());
                                                }
                                            }
                                        }
                                    }
                                    //含税单价
                                    if(UNIT_PRICE_INCLUDETAX.equals((String) entry.getKey())) {
                                        if(StringUtils.isEmpty((String) entry.getValue()) || " ".equals((String) entry.getValue())) {
                                            DrawNoVo drawNoVo = drawNoMapper.selectByPk(drawNoCode);
                                            if(!StringUtils.isEmpty(drawNoVo)) {
                                                if(!StringUtils.isEmpty(drawNoVo.getUnitPriceIncludeTax())){
                                                    //含税单价
                                                    entry.setValue(drawNoVo.getUnitPriceIncludeTax());
                                                    unitPriceIncludeTax = drawNoVo.getUnitPriceIncludeTax();
                                                }
                                            }
                                        }
                                    }
                                    //含税总价
                                    if(TOTAL_PRICE_INCLUDETAX.equals((String) entry.getKey())) {
                                        if(StringUtils.isEmpty((String) entry.getValue()) || " ".equals((String) entry.getValue())) {
                                            if(!StringUtils.isEmpty(unitPriceIncludeTax) && !StringUtils.isEmpty(quantityCompleted)) {
                                                BigDecimal totalPriceIncludeTax =new BigDecimal(String.valueOf(ArithmeticUtils.mul(unitPriceIncludeTax,quantityCompleted)));
                                                //含税总价
                                                entry.setValue(totalPriceIncludeTax);
                                            }
                                        }
                                    }

                                    //总工时
                                    if(TOTAL_WORK_TIME.equals((String) entry.getKey())) {
                                        if(StringUtils.isEmpty((String) entry.getValue()) || " ".equals((String) entry.getValue())) {
                                            if(!StringUtils.isEmpty(workTime) && !StringUtils.isEmpty(quantityCompleted)) {
                                                BigDecimal totalWorkTime =new BigDecimal(String.valueOf(ArithmeticUtils.mul(workTime,quantityCompleted)));
                                                //含税总价
                                                entry.setValue(totalWorkTime);
                                            }
                                        }
                                    }

                                    //断路器产品
                                    if(CIRCUIT_BREAKER_PRODUCT.equals((String) entry.getKey())) {
                                        if(StringUtils.isEmpty((String) entry.getValue()) || " ".equals((String) entry.getValue())) {
                                            if(modelNumber.contains("DB") || modelNumber.contains("DD") || modelNumber.contains("SB")){
                                                //设置断路器产品
                                                entry.setValue(partName);
                                            }
                                        }
                                    }
                                    //来件单位
                                    if(INCOME_PART_UNIT_CODE.equals((String) entry.getKey())) {
                                        if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                            IncomePartUnitVo incomePartUnitVo = incomePartUnitMapper.selectByPk((String) entry.getValue());
                                            if(!StringUtils.isEmpty(incomePartUnitVo)) {
                                                //设置来件单位code+name
                                                entry.setValue(incomePartUnitVo.getIncomepartunitCode()+incomePartUnitVo.getCnName());
                                            }
                                        }
                                    }
                                    //工种
                                    if(TYPE_WORK_CODE.equals((String) entry.getKey())) {
                                        if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                            TypeWorkVo typeWorkVo = typeWorkMapper.selectByPk((String) entry.getValue());
                                            if(!StringUtils.isEmpty(typeWorkVo)) {
                                                //设置工种code+name
                                                entry.setValue(typeWorkVo.getTypeworkCode()+typeWorkVo.getName());
                                            }
                                        }
                                    }
                                   /* if(INSPECTOR.equals((String) entry.getKey())) {
                                        if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                            User user = iUserDao.selectByPk((String) entry.getValue());
                                            if(!StringUtils.isEmpty(user)) {
                                                //设置检验员code+name
                                                entry.setValue(user.getJobNum()+user.getFullname());
                                            }
                                        }

                                    }*/
                                  /*  if(OPERATOR.equals((String) entry.getKey())) {
                                        User user = iUserDao.selectByPk((String) entry.getValue());
                                        //设置操作员name
                                        entry.setValue(user.getFullname());
                                    }*/
                                    if(WORK_TIME_CODE.equals((String) entry.getKey())) {
                                        if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                            WorkTimeVo workTimeVo = workTimeMapper.selectByPk((String) entry.getValue());
                                            if(!StringUtils.isEmpty(workTimeVo)) {
                                                if (!StringUtils.isEmpty(workTimeVo.getWorkTime())){
                                                    workTime = workTimeVo.getWorkTime();
                                                    //设置工时code+name
                                                    entry.setValue(String.valueOf(workTimeVo.getWorkTimeCode()+"-"+workTimeVo.getWorkTime()));
                                                }

                                            }
                                        }

                                    }
                                    if(OPERATOR.equals((String) entry.getKey())) {
                                        if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                            if (String.valueOf(entry.getValue()).contains("、")){
                                                String[] splits = String.valueOf(entry.getValue()).split("、");
                                                for (int j = 0; j < splits.length; j++) {
                                                    User user = iUserDao.selectByJobNum(splits[j]);
                                                    if (j == 0){
                                                        operator.append(splits[j]+user.getFullname());
                                                    }else {
                                                        operator.append("、").append(splits[j]+user.getFullname());
                                                    }
                                                }
                                            }else {
                                                User user = iUserDao.selectByJobNum(String.valueOf(entry.getValue()));
                                                operator.append(String.valueOf(entry.getValue())+user.getFullname());
                                            }
                                            if(!StringUtils.isEmpty(operator)) {
                                                //设置工时code+name
                                                entry.setValue(operator);
                                            }
                                        }
                                    }

                                    if(CREATOR.equals((String) entry.getKey())) {
                                        if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                            User user = iUserDao.selectByJobNum((String) entry.getValue());
                                            if(!StringUtils.isEmpty(user)) {
                                                //设置工时code+name
                                                entry.setValue((String) entry.getValue()+user.getFullname());
                                            }
                                        }
                                    }
                                    /*if(WORK_TIME_CODE.equals((String) entry.getKey())) {
                                        if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                            WorkTimeVo workTimeVo = workTimeMapper.selectByPk((String) entry.getValue());
                                            if(!StringUtils.isEmpty(workTimeVo)) {
                                                //设置工时code+name
                                                entry.setValue(String.valueOf(workTimeVo.getWorkTimeCode()+workTimeVo.getWorkTime()));
                                            }
                                        }
                                    }*/
                                   /* if(CREATOR.equals((String) entry.getKey())) {
                                        if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                            User user = iUserDao.selectByPk((String) entry.getValue());
                                            if(!StringUtils.isEmpty(user)) {
                                                //设置创建者code+name
                                                entry.setValue(user.getJobNum()+user.getFullname());
                                            }
                                        }

                                    }
                                    if(MODIFIER.equals((String) entry.getKey())) {
                                        if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                            User user = iUserDao.selectByPk((String) entry.getValue());
                                            if(!StringUtils.isEmpty(user)) {
                                                //设置修改者code+name
                                                entry.setValue(user.getJobNum()+user.getFullname());
                                            }
                                        }

                                    }*/
                                    //zww 公式赋值开始
                                    //赋初始值 即无公式时取默认值
                                    String formulaValue = null;
                                    if (!StringUtils.isEmpty(entry.getValue())) {
                                        formulaValue = entry.getValue().toString();
                                    }
                                    try {
                                        //获取公式
                                        String formula = incomePartJudgeFieldMapper.selectFormulaByEnFieldName((String) entry.getKey());
                                        //获取公式计算值
                                        if (!StringUtils.isEmpty(formula) && !StringUtils.isEmpty(id)) {
                                            //有公式取公式值
                                            if (!StringUtils.isEmpty(FormulaUtils.calculation(formula, id))) {
                                                formulaValue = FormulaUtils.calculation(formula, id);
                                            }
                                        }
                                    }
                                    catch (Exception e) {
                                        //事务手动回滚
                                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                        //遇到异常，返回异常原因
                                        e.printStackTrace();
                                        return ResponseTemplate.builder().code(1).message("请检查公式中对应的科目号类型是否符合运算条件,如中文名称不可加减乘除").count(0l).build();
                                    }
                                    //zww 公式赋值结束

                                    linkedHashMap.put(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, (String) entry.getKey()), formulaValue);
                                }
                                //重置将key驼峰
                                secondList.set(i, linkedHashMap);

                            }
                        }
                        //构造分页实体
                        PageInfo<LinkedHashMap> info = new PageInfo<>(secondList);
                        map.put("secondList", secondList);
                        if (info.getTotal() > 0) {
                            //查询到数据
                            return ResponseTemplate.builder().code(0).message("查询成功").count((long) info.getTotal()).data(map).build();
                        } else {
                            //没有查询到数据
                            return ResponseTemplate.builder().code(1).message("没有查到对应数据").count(0l).build();
                        }



                } else {
                    return ResponseTemplate.builder().code(1).message("来料接收与判定字段均未启用").count(0l).build();
                }
            } catch (Exception e) {
                //事务手动回滚
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                //遇到异常，返回异常原因
                e.printStackTrace();
                return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
            }
        } else {
            return ResponseTemplate.builder().code(1).message("分页参数错误").count(0l).build();
        }
    }

    /**
     *@Description://插入一条记录
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/08
     */
    @Override
    public ResponseTemplate insert(IncomePartJudgeVo incomePartJudgeVo) {

        try {
            lock.lock();
            User user = iUserDao.selectByPk(incomePartJudgeVo.getCreator());
            incomePartJudgeVo.setCreator(user.getJobNum());
            String sql = getIncomePartJudgeEnableFieldInsert();
            String sqlvalue = dbFieldToPojoField();
            int id = getIncomePartJudgeId();
            incomePartJudgeVo.setId(id);

            //生成工单号 AVIC2020111700001A
            //1.获取当前日期
            String currentDate = HexUtil.getCurrentDateYYYYMMDD();
            String dataStr="%"+currentDate+"%";
            LinkedHashMap listmap = incomePartJudgeMapper.selectWorkOrderNumber(dataStr);
            int count = Integer.valueOf(String.valueOf(listmap.get("number")));
            String newWorkOrderNumber="";
            if (count != 0){//不为空
                //根据已存在数+1 生成工单号
                String format = String.format("%05d", count+1);
                newWorkOrderNumber = SIGN + currentDate + format + COMPLETE_LIST_SIGN;
            }else {//为空
                String format = String.format("%05d", 1);//00001
                newWorkOrderNumber =  SIGN + currentDate + format + COMPLETE_LIST_SIGN;
            }
            //设置新的工单号
            incomePartJudgeVo.setWorkOrderNumber(newWorkOrderNumber);


            if (StringUtils.isEmpty(incomePartJudgeVo.getIncomePartUnitCode())){
                return ResponseTemplate.builder().code(1).message("来件单位不能为空！").count(0l).build();
            }
            if (StringUtils.isEmpty(incomePartJudgeVo.getDrawNoCode())){
                return ResponseTemplate.builder().code(1).message("图号不能为空！").count(0l).build();
            }
            if (StringUtils.isEmpty(incomePartJudgeVo.getTypeWorkCode())){
                return ResponseTemplate.builder().code(1).message("工种不能为空！").count(0l).build();
            }
            if (StringUtils.isEmpty(incomePartJudgeVo.getIncomePartQuantity())){
                return ResponseTemplate.builder().code(1).message("来件数量不能为空！").count(0l).build();
            }
            if (StringUtils.isEmpty(incomePartJudgeVo.getIncomePartQuantity())){
                return ResponseTemplate.builder().code(1).message("来件时间不能为空！").count(0l).build();
            }

            //判断是已完成的台账，还是生产计划
            incomePartJudgeVo.setDeleteFlag("1");
            if(!StringUtils.isEmpty(incomePartJudgeVo.getUnfinishedQuantity())&&!StringUtils.isEmpty(incomePartJudgeVo.getIncomePartQuantity())
            &&StringUtils.isEmpty(incomePartJudgeVo.getTimeCompletedOne()) && "合格".equals(incomePartJudgeVo.getIncomePartJudgeResult())) {
                if(incomePartJudgeVo.getUnfinishedQuantity().equals(incomePartJudgeVo.getIncomePartQuantity())){
                    incomePartJudgeVo.setDeleteFlag("2");
                }
            }
            //完成数量为空时，未完成数量等于来件数量
            if(StringUtils.isEmpty(incomePartJudgeVo.getQuantityCompleted()) || ZERO.equals(incomePartJudgeVo.getQuantityCompleted()) ){
                incomePartJudgeVo.setUnfinishedQuantity(incomePartJudgeVo.getIncomePartQuantity());
            }



            if (!StringUtils.isEmpty(sql)) {
                    //没有异常并且插入数据条数大于0
                    int rows = incomePartJudgeMapper.insert(incomePartJudgeVo,sql,sqlvalue);


                //往在工表里 工单表里 生产实绩表里插入相应数据
                if (TWO.equals(incomePartJudgeVo.getDeleteFlag())) {
                    Route route = mainProductionMapper.selectRouteOne();
                    //工单表
                    WorkOrder workOrder = new WorkOrder();
                    workOrder.setWorkOrderNumber(incomePartJudgeVo.getWorkOrderNumber());
                    workOrder.setIncomePartUnitCode(incomePartJudgeVo.getIncomePartUnitCode());
                    workOrder.setModelNumber(incomePartJudgeVo.getModelNumber());
                    workOrder.setModelType(incomePartJudgeVo.getModelType());
                    workOrder.setDrawNoCode(incomePartJudgeVo.getDrawNoCode());
                    workOrder.setPartName(incomePartJudgeVo.getPartName());
                    workOrder.setHeatSurfaceSequence(incomePartJudgeVo.getHeatSurfaceSequence());
                    workOrder.setTypeWorkCode(incomePartJudgeVo.getTypeWorkCode());
                    workOrder.setIncomePartQuantity(incomePartJudgeVo.getIncomePartQuantity());
                    workOrder.setIncomePartTime(incomePartJudgeVo.getIncomePartTime());
                    workOrder.setOrderNumber(incomePartJudgeVo.getOrderNumber());
                    workOrder.setState(ZERO);
                    workOrder.setCurrentLocation(route.getId());
                    workOrder.setCurrentQuantity(incomePartJudgeVo.getIncomePartQuantity());
                    workOrder.setCreator(incomePartJudgeVo.getCreator());
                    workOrder.setCreateTime(incomePartJudgeVo.getCreateTime());
                    mainProductionMapper.insertWorkOrder(workOrder);
                    //在工表
                    WIP wip = new WIP();
                    wip.setWorkOrderNumber(incomePartJudgeVo.getWorkOrderNumber());
                    wip.setState(ZERO);
                    wip.setCurrentLocation(route.getId());
                    wip.setEntryTime(incomePartJudgeVo.getCreateTime());
                    wip.setEntryPerson(incomePartJudgeVo.getCreator());
                    wip.setCurrentQuantity(incomePartJudgeVo.getIncomePartQuantity());
                    mainProductionMapper.insertWIP(wip);
                    //生产实际表
                    OrderResource orderResource = new OrderResource();
                    orderResource.setWorkOrderNumber(incomePartJudgeVo.getWorkOrderNumber());
                    orderResource.setOrderNumber(incomePartJudgeVo.getOrderNumber());
                    orderResource.setEntryTime(incomePartJudgeVo.getCreateTime());
                    orderResource.setEntryPerson(incomePartJudgeVo.getCreator());
                    orderResource.setState(ZERO);
                    orderResource.setRoutePosition(route.getId());
                    orderResource.setCurrentQuantity(incomePartJudgeVo.getIncomePartQuantity());
                    mainProductionMapper.insertOrderResource(orderResource);
                }



                    if (rows > 0) {
                        return ResponseTemplate.builder().code(0).message("插入数据成功").count(1l).build();
                    } else {//没有异常并且插入数据失败，原则上不出现
                        return ResponseTemplate.builder().code(1).message("插入数据失败").count(0l).build();
                    }

            }
            else {
                return ResponseTemplate.builder().code(1).message("不支持添加").count(0l).build();
            }
        } catch (Exception e) {
            //事务手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //出现异常返回异常原因
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }
        finally {
            lock.unlock();
        }
    }


    /**
     *@Description:批量插入记录
     *@Param: [listIncomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/08
     */
    @Override
    public ResponseTemplate batchInsert(List<IncomePartJudgeVo> listIncomePartJudgeVo) {
        if(!listIncomePartJudgeVo.isEmpty()) {
            String pk = "";
            try {
                lock.lock();
                for (IncomePartJudgeVo incomePartJudgeVo : listIncomePartJudgeVo) {
                    pk = UUIDUtils.getUUID();
                    incomePartJudgeVo.setOrderNumber(pk);
                }
                //没有异常并且插入数据条数大于0
                int rows = incomePartJudgeMapper.batchInsert(listIncomePartJudgeVo);
                if (rows > 0) {
                    return ResponseTemplate.builder().code(0).message("批量插入数据成功").count((long)rows).build();
                } else {//没有异常并且插入数据失败，原则上不出现
                    return ResponseTemplate.builder().code(1).message("批量插入数据失败").count(0l).build();
                }
            } catch (Exception e) {
                //事务手动回滚
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                //出现异常返回异常原因
                e.printStackTrace();
                return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
            }
            finally {
                lock.unlock();
            }
        }
        else {
            return ResponseTemplate.builder().code(1).message("传入参数为空").count(0l).build();
        }
    }
    /**
     *@Description:逻辑删除一条记录
     *@Param: [orderNumber]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/08
     */
    @Override
    public ResponseTemplate delete(String id,String userName) {


            try {
                lock.lock();
                //查询来件时间
                IncomePartJudgeVo incomePartJudgeVo = incomePartJudgeMapper.selectById(id);
                if(!StringUtils.isEmpty(incomePartJudgeVo)&&!StringUtils.isEmpty(incomePartJudgeVo.getIncomePartTime())) {
                    //获取当前日期
                    Date currentDate = new Date();
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    String dateString=sdf.format(currentDate)+" 23:59:59";
                    //当天结束日期时间
                    Date dateEnd=sdf.parse(dateString);
                    //来件时间
                    Date incomePartDate=sdf.parse(incomePartJudgeVo.getIncomePartTime());
                    if(incomePartDate.getTime()<=dateEnd.getTime()){
                        return ResponseTemplate.builder().code(1).message("不能删除当天及之前的数据!").count(0l).build();
                    }
                    else{//来件时间大于当天，可以删除
                        String sql = getIncomePartJudgeEnableField();
                        User user = iUserDao.selectByPk(userName);

                        int rows = incomePartJudgeMapper.delete(id, user.getJobNum());
                        //判断删除操作是否成功
                        if (rows > 0) {
                            //删除成功返回数据
                            return ResponseTemplate.builder().code(0).message("删除成功").count(1l).build();
                        } else {
                            //删除失败返回提示
                            return ResponseTemplate.builder().code(1).message("删除失败").count(0l).build();
                        }
                    }
                }
                else{
                    return ResponseTemplate.builder().code(1).message("请输入来件时间").count(0l).build();
                }
            } catch (Exception e) {
                //事务手动回滚
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                //遇到异常，返回异常原因
                e.printStackTrace();
                return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
            }
            finally {
                lock.unlock();
            }
    }
    /**
     *@Description:通过pks批量逻辑删除记录
     *@Param: [listPks]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/08
     */
    @Override
    public ResponseTemplate batchDeleteByPks(List<String> listPks) {
        if(!listPks.isEmpty()) {
            try {
                lock.lock();
                //非空pklist后去除不合法pk
                for (String pk:listPks) {
                    //校验pk合法性
                    if (!UUIDUtils.checkPk(pk)){
                        listPks.remove(pk);
                    }
                }
                //长度为一的list再次进行pk合法性判断
                if(listPks.size()==1&&!UUIDUtils.checkPk(listPks.get(0))) {
                    listPks.clear();
                }
                //没有合法的pk返回前端
                if(listPks.size()==0) {
                    return ResponseTemplate.builder().code(1).message("没有合法的pk值").count(0l).build();
                }
                else {
                    //存在合法pk值，进行批量删除操作
                    int rows = incomePartJudgeMapper.batchDeleteByPks(listPks);
                    //判断批量删除操作是否成功
                    if (rows > 0) {
                        //批量删除成功返回数据
                        return ResponseTemplate.builder().code(0).message("批量删除成功").count((long)rows).build();
                    } else {
                        //批量删除失败返回提示
                        return ResponseTemplate.builder().code(1).message("批量删除失败").count(0l).build();
                    }
                }
            } catch (Exception e) {
                //事务手动回滚
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                //遇到异常，返回异常原因
                e.printStackTrace();
                return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
            }
            finally {
                lock.unlock();
            }
        }
        else {
            return ResponseTemplate.builder().code(1).message("传入参数为空").count(0l).build();
        }
    }
    /**
     *@Description:修改一条记录
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/08
     */
    @Override
    public ResponseTemplate update(IncomePartJudgeVo incomePartJudgeVo) {
        try {
            lock.lock();
            if(!StringUtils.isEmpty(incomePartJudgeVo.getIncomePartTime())) {
                //获取当前日期
                Date currentDate = new Date();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                String dateString=sdf.format(currentDate)+" 23:59:59";
                //当天结束日期时间
                Date dateEnd=sdf.parse(dateString);
                //来件时间
                Date incomePartDate=sdf.parse(incomePartJudgeVo.getIncomePartTime());
                if(incomePartDate.getTime()<=dateEnd.getTime()){
                    return ResponseTemplate.builder().code(1).message("不能编辑当天及之前的数据!").count(0l).build();
                }
                else{//来件时间大于当天，可以编辑
                    User user = iUserDao.selectByPk(incomePartJudgeVo.getModifier());
                    incomePartJudgeVo.setModifier(user.getJobNum());
                    String sqlupdate = getIncomePartJudgeEnableFieldForUpdate();
                    if (!StringUtils.isEmpty(sqlupdate)) {
                        //没有异常并且修改数据条数大于0
                        int rows = incomePartJudgeMapper.update(incomePartJudgeVo, sqlupdate);
                        if (rows > 0) {
                            return ResponseTemplate.builder().code(0).message("修改数据成功").count(1l).build();
                        } else {//没有异常并且修改数据失败，原则上不出现
                            return ResponseTemplate.builder().code(1).message("修改数据失败").count(0l).build();
                        }

                    }
                    else {
                        return ResponseTemplate.builder().code(1).message("无法修改").count(0l).build();
                    }
                }
            }
            else{
                return ResponseTemplate.builder().code(1).message("请输入来件时间").count(0l).build();
            }
        } catch (Exception e) {
            //事务手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            //出现异常返回异常原因
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }
        finally {
            lock.unlock();
        }
    }

    @Override
    public ResponseTemplate selectTotalIncomepartjudge() {
        try {
            //将返回的数据封装为map集合
            Map<String, Object> map = new HashMap<>();
            //1.获取第一个数组
            //查询来料接收与判定表字段表启用字段的相关信息(根据orderid排序)
            List<IncomePartJudgeFieldVo> incomePartJudgeFieldVos = incomePartJudgeFieldMapper.selectEnableFieldInfo();
            List<IncomePartJudgeFieldVo> incomePartJudgeFieldHumpVos = incomePartJudgeFieldVos;
            if (incomePartJudgeFieldHumpVos.size()>0) {
                for(IncomePartJudgeFieldVo incomePartJudgeFieldVo:incomePartJudgeFieldHumpVos) {
                    incomePartJudgeFieldVo.setEnfieldName(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, incomePartJudgeFieldVo.getEnfieldName()));
                }

            }
            //1.存放第一个数组
            map.put("firstList", incomePartJudgeFieldHumpVos);
            if (ListUtil.isEmpty(incomePartJudgeFieldVos)) {
                //为空的情况下放一个空数组数据
                map.put("secondList", new ArrayList<>());
            } else {//不为空
                //2.获取第二个数组
                StringBuilder sb = new StringBuilder(); //拼接sql 查询的参数

                for (int i = 0; i < incomePartJudgeFieldVos.size(); i++) {
                    //存放在LinkedHashMap中  后面方面有序的进行传参
                    sb.append("`");
                    sb.append(incomePartJudgeFieldVos.get(i).getEnfieldName());
                    sb.append("`");
                    if (i != incomePartJudgeFieldVos.size() - 1) {//不是最后一个就 拼接一个,
                        sb.append(",");
                    }
                }
                String sql = sb.toString();
                System.out.println("拼接的sql：" + sql);
                log("拼接的sql:" + sql);
                //根据map中的key获取对应列的数值
                List<LinkedHashMap> secondList = incomePartJudgeFieldMapper.selectDateByKey(sql);
                map.put("secondList", secondList);

            }
            return ResponseTemplate.builder().code(0).message("来料主表的总查询查询接口返回数据成功").data(map).build();
        } catch (Exception e) {
            //事务手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).build();
        }
    }


    /**
     *@Description:获取来料接收与判定字段表所有启用字段并且拼接sql(查询用)
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/10
     */
    private String getIncomePartJudgeEnableField() {
        String sql = "";
        //来料接收与判定字段实体链表
        List<IncomePartJudgeFieldVo> listIncomePartJudgeFieldVo = incomePartJudgeFieldMapper.selectEnableFieldInfo1();
        //非空判断
        if (!StringUtils.isEmpty(listIncomePartJudgeFieldVo)) {
            StringBuilder sb = new StringBuilder();
            //开始拼接sql
            for (int i = 0; i < listIncomePartJudgeFieldVo.size(); i++) {
                //if(!"delete_flag".equals(listIncomePartJudgeFieldVo.get(i).getEnfieldName())) {
                    sb.append("a.");
                    sb.append("`");
                    sb.append(listIncomePartJudgeFieldVo.get(i).getEnfieldName());
                    sb.append("`");
                    if (i != listIncomePartJudgeFieldVo.size() - 1) {
                        sb.append(",");
                    }
                //}

            }
            sql = sb.toString();
        }
        return sql;
    }
    /**
     *@Description: 获取来料接收与判定字段表所有启用字段并且拼接sql(查询字段插入用)
     *@Param: []
     *@return: java.lang.String
     *@Author: xxc
     *@date: 2020/11/9
     */
    private String getIncomePartJudgeEnableFieldInsert() {
        String sql = "";
        //来料接收与判定字段实体链表
        List<IncomePartJudgeFieldVo> listIncomePartJudgeFieldVo = incomePartJudgeFieldMapper.selectEnableFieldInfo1();
        //非空判断
        if (!StringUtils.isEmpty(listIncomePartJudgeFieldVo)) {
            StringBuilder sb = new StringBuilder();
            //开始拼接sql
            for (int i = 0; i < listIncomePartJudgeFieldVo.size(); i++) {
                sb.append("`");
                sb.append(listIncomePartJudgeFieldVo.get(i).getEnfieldName());
                sb.append("`");
                if (i != listIncomePartJudgeFieldVo.size() - 1) {
                    sb.append(",");
                }

            }
            sql = sb.toString();
        }
        return sql;

    }
    /**
     *@Description:获取来料接收与判定字段表所有启用字段并且拼接sql(非权限数据查询用)
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/10
     */
    private String getIncomePartJudgeEnableNotAuthField() {
        String sql = "";
        //来料接收与判定字段实体链表
        List<IncomePartJudgeFieldVo> listIncomePartJudgeFieldVo = incomePartJudgeFieldMapper.selectEnableNotAuthFieldInfo();
        //非空判断
        if (!StringUtils.isEmpty(listIncomePartJudgeFieldVo)) {
            StringBuilder sb = new StringBuilder();
            //开始拼接sql
            for (int i = 0; i < listIncomePartJudgeFieldVo.size(); i++) {
               // if(!"delete_flag".equals(listIncomePartJudgeFieldVo.get(i).getEnfieldName())) {
                    sb.append("a.");
                    sb.append("`");
                    sb.append(listIncomePartJudgeFieldVo.get(i).getEnfieldName());
                    sb.append("`");
                    if (i != listIncomePartJudgeFieldVo.size() - 1) {
                        sb.append(",");
                    }
               // }

            }
            sql = sb.toString();
        }
        return sql;
    }
    /**
     *@Description: 获取当前要插入数据的id
     *@Param: []
     *@return: java.lang.Integer
     *@Author: xxc
     *@date: 2020/10/26
     */
    private int getIncomePartJudgeId() {
        int id = 1;
        String lastId = incomePartJudgeMapper.selectMaxId();
        if (!StringUtils.isEmpty(lastId)) {
            id = Integer.parseInt(lastId ) +1;
        }
        return id;
    }

    /**
     *@Description:将数据库字段转为实体驼峰字段并拼接(插入数据数值插入用)
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/13
     */
    private  String dbFieldToPojoField() {
        String sqlValue = "";
        //来料接收与判定字段实体链表
        List<IncomePartJudgeFieldVo> listIncomePartJudgeFieldVo = incomePartJudgeFieldMapper.selectEnableFieldInfo1();
        //非空判断
        if (!StringUtils.isEmpty(listIncomePartJudgeFieldVo)) {
            StringBuilder sb = new StringBuilder();
            //开始拼接sql
            for (int i = 0; i < listIncomePartJudgeFieldVo.size(); i++) {
                //数据库列字段驼峰如create_time转为createTime
                if("createTime".equals(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, listIncomePartJudgeFieldVo.get(i).getEnfieldName()))) {
                    Date date = new Date();//获取当前的日期
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
                    String strDate = df.format(date);//获取String类型的时间
                    sb.append("\"");
                    sb.append(strDate);
                    sb.append("\"");
                }
                //其他启用字段
                else {
                    sb.append("#{");
                    sb.append("incomePartJudgeVo.");
                    sb.append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, listIncomePartJudgeFieldVo.get(i).getEnfieldName()));
                    sb.append("}");
                }
                if (i != listIncomePartJudgeFieldVo.size() - 1) {
                    sb.append(",");
                }

            }
            sqlValue = sb.toString();
        }
        return sqlValue;
    }

     /**
     *@Description:获取来料接收与判定字段表所有启用字段并且拼接sql(修改用)
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/13
     */
    private String getIncomePartJudgeEnableFieldForUpdate() {
        String sqlupdate = "";
        //来料接收与判定字段实体链表
        List<IncomePartJudgeFieldVo> listIncomePartJudgeFieldVo = incomePartJudgeFieldMapper.selectEnableFieldInfo();
        //非空判断
        if (!StringUtils.isEmpty(listIncomePartJudgeFieldVo)) {
            StringBuilder sb = new StringBuilder();
            //开始拼接sql
            for (int i = 0; i < listIncomePartJudgeFieldVo.size(); i++) {
                //不修改数据库字段
/*                if("orderNumber".equals(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, listIncomePartJudgeFieldVo.get(i).getEnfieldName()))) {
                }*/
                //修改更改时间
                if("updateTime".equals(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, listIncomePartJudgeFieldVo.get(i).getEnfieldName()))) {
                    sb.append("`");
                    sb.append(listIncomePartJudgeFieldVo.get(i).getEnfieldName());
                    sb.append("`");
                    sb.append("=");
                    Date date = new Date();//获取当前的日期
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
                    String strDate = df.format(date);//获取String类型的时间
                    sb.append("\"");
                    sb.append(strDate);
                    sb.append("\"");
                }
                //不修改创建时间
                else if("createTime".equals(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, listIncomePartJudgeFieldVo.get(i).getEnfieldName()))) {
                }
                //不修改逻辑删除标志
                else if("deleteFlag".equals(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, listIncomePartJudgeFieldVo.get(i).getEnfieldName()))) {
                }
                //其他启用字段
                else {
                    sb.append("`");
                    sb.append(listIncomePartJudgeFieldVo.get(i).getEnfieldName());
                    sb.append("`");
                    sb.append("=");
                    sb.append("#{");
                    sb.append("incomePartJudgeVo.");
                    sb.append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, listIncomePartJudgeFieldVo.get(i).getEnfieldName()));
                    sb.append("}");
                }
                //&&i != 0
                if (i != listIncomePartJudgeFieldVo.size() - 1
                        &&!"deleteFlag".equals(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, listIncomePartJudgeFieldVo.get(i).getEnfieldName()))
                        &&!"createTime".equals(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, listIncomePartJudgeFieldVo.get(i).getEnfieldName()))) {
                    sb.append(",");
                }

            }
            sqlupdate = sb.toString();
        }
        return sqlupdate;
    }
    /**
     *@Description:生成来料主表订单号
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/14
     */
    @Override
    public ResponseTemplate getIncomePartJudgeOrderNo() {
        try {
            Date date = new Date();//获取当前的日期
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
            String strDate = df.format(date);//获取String类型的时间
            int drawNoCount = drawNoMapper.selectCurrentDrawNoCount(strDate)+1;
            String orderNo = OrderNoUtils.generateOrderNo(String.valueOf(drawNoCount));
            return ResponseTemplate.builder().code(0).message("生成订单号成功").data(orderNo).count(1l).build();
        }catch (Exception e) {
            //事务手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }
    }
    /**
     *@Description: 获取序
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/9
     */
    @Override
    public ResponseTemplate getId() {
        try {
            //序
            int idNum = getIncomePartJudgeId();
            String id = String.valueOf(idNum);
/*            Date date = new Date();//获取当前的日期
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            String strDate = df.format(date);//获取String类型的时间
            int drawNoCount = drawNoMapper.selectCurrentDrawNoCount(strDate);
            String orderNo = OrderNoUtils.generateOrderNo(String.valueOf(drawNoCount));*/
            return ResponseTemplate.builder().code(0).message("生成序成功").data(id).count(1l).build();
        }catch (Exception e) {
            //事务手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }
    }

    /**
     *@Description:生成来料主表含税单价
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/14
     */
    @Override
    public ResponseTemplate getIncomePartJudgeUnitPrice(String drawNoCode) {
        try {

            //根据pk查询图号记录
            DrawNoVo drawNoVo = drawNoMapper.selectByPk(drawNoCode);
            if(!BeanUtil.isEmpty(drawNoVo)) {
                return ResponseTemplate.builder().code(0).message("生成含税单价成功").data(drawNoVo.getUnitPriceIncludeTax()).count(1l).build();
            }
            else {
                return ResponseTemplate.builder().code(0).message("请到图号管理中填入含税单价").data(null).count(1l).build();
            }

        }catch (Exception e) {
            //事务手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }
    }
    /**
     *@Description: 生成来料主表含税总价
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/19
     */
    @Override
    public ResponseTemplate getIncomePartJudgeUnitTotalPrice(IncomePartJudgeVo incomePartJudgeVo) {
        try {
            if (Integer.parseInt(incomePartJudgeVo.getQuantityCompleted())>0){
                incomePartJudgeVo.setTotalPriceIncludeTax(String.valueOf(new BigDecimal(incomePartJudgeVo.getUnitPriceIncludeTax()).multiply(new BigDecimal(Integer.parseInt(incomePartJudgeVo.getQuantityCompleted())))));
                return ResponseTemplate.builder().code(0).message("计算总价成功").data(incomePartJudgeVo.getTotalPriceIncludeTax()).count(1l).build();

            }
            else {
                return ResponseTemplate.builder().code(0).message("请填入完成数量").data(null).count(1l).build();
            }

        }catch (Exception e) {
            //事务手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }

    }

    /**
     *@Description: 获取工时
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/19
     */
    @Override
    public ResponseTemplate getIncomePartJudgeUnitWorkTime(IncomePartJudgeVo incomePartJudgeVo) {
        try {

            //查询数据库是否有对应图号编码的工时
            WorkTimeVo workTimeVo = workTimeMapper.selectByDrawNoTypeWork(incomePartJudgeVo.getDrawNoCode(),incomePartJudgeVo.getTypeWorkCode());
            if(!StringUtils.isEmpty(workTimeVo)) {

                return ResponseTemplate.builder().code(0).message("获取工时成功").data(workTimeVo).count(1l).build();
            }
            else {
                return ResponseTemplate.builder().code(0).message("未获取到工时").data(null).count(1l).build();
            }

        }catch (Exception e) {
            //事务手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }

    }
    /**
     *@Description: 获取总工时
     *@Param: [incomePartJudgeVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/19
     */
    @Override
    public ResponseTemplate getIncomePartJudgeUnitTotalWorkTime(IncomePartJudgeVo incomePartJudgeVo) {
        try {

            if (Integer.parseInt(incomePartJudgeVo.getIncomePartQuantity())>0){
                WorkTimeVo workTimeVo = workTimeMapper.selectByPk(incomePartJudgeVo.getWorkTimeCode());
                BigDecimal workTime = new BigDecimal(workTimeVo.getWorkTime());
                incomePartJudgeVo.setTotalWorkTime(String.valueOf(workTime.multiply(new BigDecimal(incomePartJudgeVo.getIncomePartQuantity()))));
                return ResponseTemplate.builder().code(0).message("计算总工时成功").data(incomePartJudgeVo.getTotalPriceIncludeTax()).count(1l).build();

            }
            else {
                return ResponseTemplate.builder().code(0).message("请填入完成数量").data(null).count(1l).build();
            }

        }catch (Exception e) {
            //事务手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }

    }
    /**
     *@Description: 获取前端表头信息
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/21
     */
    @Override
    public ResponseTemplate getIncomePartField() {
        try {


                //查询来料接收与判定表字段表启用字段的相关信息(根据orderid排序)
                List<IncomePartJudgeFieldVo> incomePartJudgeFieldVos = incomePartJudgeFieldMapper.selectEnableFieldInfo();
                //驼峰字段信息
                List<IncomePartJudgeFieldVo> incomePartJudgeFieldHumpVos = incomePartJudgeFieldVos;
                //返回前端渲染表头list
                List<IncomePartFieldForFront> incomePartFieldList = new ArrayList<IncomePartFieldForFront>();
                if (incomePartJudgeFieldHumpVos.size() > 0) {
                    for (int i=0;i<incomePartJudgeFieldHumpVos.size();i++) {
                        if(!"delete_flag".equals(incomePartJudgeFieldHumpVos.get(i).getEnfieldName())) {
                            //新建前端表头显示对象
                            IncomePartFieldForFront incomePartFieldForFront= new IncomePartFieldForFront();
                            //设置字段名称
                            incomePartFieldForFront.setField(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, incomePartJudgeFieldHumpVos.get(i).getEnfieldName()));
                            //设置中文名称
                            incomePartFieldForFront.setTitle(incomePartJudgeFieldHumpVos.get(i).getCnfieldName());
                            //设置位置
                            incomePartFieldForFront.setAlign(CENTER);
                            //添加对象到list中
                            incomePartFieldList.add(i,incomePartFieldForFront);
                        }
                    }
                    return ResponseTemplate.builder().code(0).message("获取表头信息成功").data(incomePartFieldList).count(0l).build();

                }
                else {
                    return ResponseTemplate.builder().code(1).message("无可用表头信息").count(0l).build();
                }
        }
            catch(Exception e) {
                //事务手动回滚
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                e.printStackTrace();
                return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
            }
    }
    /**
     *@Description:查询所有非权限数据
     *@Param: [page, limit, idOrName]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/10/26
     */
    @Override
    public ResponseTemplate selectAllNotAuthData(String page, String limit,String beginTime,String endTime, String idOrName) {
        //校验分页参数是否为纯数字 并且page和limit不都等于0
        if (Validator.isNumber(page) && Validator.isNumber(limit) && !("0".equals(page) && "0".equals(limit))) {
            try {
                //来料接收与判定字段启用字段
                String sql = getIncomePartJudgeEnableNotAuthField();
                System.out.println("===========>sql:" + sql + "========>");
                if (!StringUtils.isEmpty(sql)) {


                    //将返回的数据封装为map集合
                    Map<String, Object> map = new HashMap<>();
                    //1.获取第一个数组
                    //查询来料接收与判定表字段表非权限启用字段的相关信息(根据orderid排序)
                    List<IncomePartJudgeFieldVo> incomePartJudgeFieldVos = incomePartJudgeFieldMapper.selectEnableNotAuthFieldInfo();
                   /* for (Iterator<IncomePartJudgeFieldVo> iterator = incomePartJudgeFieldVos.iterator(); iterator.hasNext();) {
                        IncomePartJudgeFieldVo incomePartJudgeFieldVo = iterator.next();
                        if ("delete_flag".equals(incomePartJudgeFieldVo.getEnfieldName())) {
                            iterator.remove();
                        }
                    }*/
                    //驼峰字段信息
                    List<IncomePartJudgeFieldVo> incomePartJudgeFieldHumpVos = incomePartJudgeFieldVos;
                    if (incomePartJudgeFieldHumpVos.size() > 0) {
                        for (IncomePartJudgeFieldVo incomePartJudgeFieldVo : incomePartJudgeFieldHumpVos) {
                            incomePartJudgeFieldVo.setEnfieldName(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, incomePartJudgeFieldVo.getEnfieldName()));
                        }

                    }
                    //1.存放第一个数组
                    map.put("firstList", incomePartJudgeFieldHumpVos);


                    System.out.println("拼接的sql：" + sql);
                    log("拼接的sql:" + sql);
                    PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
                    if (StringUtils.isEmpty(beginTime)){
                        beginTime= "1970-01-01";//HexUtil.getCurrentDate();
                    }
                    if (StringUtils.isEmpty(endTime)){
                        endTime= "2100-12-30";//HexUtil.getCurrentDate();
                    }
                    //根据map中的key获取对应列的数值
                    List<LinkedHashMap> secondList = new ArrayList<>();
                    //判断模糊查询是否为状态查询 启用为 1 禁用为 0
                    if (!StringUtils.isEmpty(idOrName)){
                        //启用
                        if (UNFINISHED.equals(idOrName)){
                            idOrName = TWO;
                            String state = BASICINFORMATIONSOURCE;
                            secondList = incomePartJudgeMapper.selectByDeleteFlag(sql,beginTime ,endTime, idOrName, state);
                            //模糊查询
                        } else {
                            secondList = incomePartJudgeMapper.selectAllData(sql,beginTime ,endTime, idOrName);
                        }
                    }else {
                        //全局查询
                        secondList = incomePartJudgeMapper.selectAllData(sql,beginTime ,endTime, idOrName);
                    }
                    if (secondList.size()>0) {

                        for (int i = 0; i < secondList.size(); i++) {
                            //获取每条数据的序 id
                            String id = secondList.get(i).get("id").toString();
                            Iterator it = secondList.get(i).entrySet().iterator();
                            LinkedHashMap linkedHashMap = new LinkedHashMap();
                            //获取每条数据的操作人
                            StringBuffer operator = new StringBuffer();
                            while (it.hasNext()) {

                                Map.Entry entry = (Map.Entry) it.next();
                                if(DRAW_NO_CODE.equals((String) entry.getKey())) {
                                    if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                        DrawNoVo drawNoVo = drawNoMapper.selectByPk((String) entry.getValue());
                                        if(!StringUtils.isEmpty(drawNoVo)) {
                                            //设置图号code+name
                                            entry.setValue(drawNoVo.getDrawNoCode()+"-"+drawNoVo.getName());
                                        }
                                    }
                                }
                                if(INCOME_PART_UNIT_CODE.equals((String) entry.getKey())) {
                                    if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                        IncomePartUnitVo incomePartUnitVo = incomePartUnitMapper.selectByPk((String) entry.getValue());
                                        if(!StringUtils.isEmpty(incomePartUnitVo)) {
                                            //设置来件单位code+name
                                            entry.setValue(incomePartUnitVo.getIncomepartunitCode()+incomePartUnitVo.getCnName());
                                        }
                                    }
                                }
                                if(TYPE_WORK_CODE.equals((String) entry.getKey())) {
                                    if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                        TypeWorkVo typeWorkVo = typeWorkMapper.selectByPk((String) entry.getValue());
                                        if(!StringUtils.isEmpty(typeWorkVo)) {
                                            //设置工种code+name
                                            entry.setValue(typeWorkVo.getTypeworkCode()+typeWorkVo.getName());
                                        }
                                    }
                                }
                              /*  if(INSPECTOR.equals((String) entry.getKey())) {
                                    if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                        User user = iUserDao.selectByPk((String) entry.getValue());
                                        if(!StringUtils.isEmpty(user)) {
                                            //设置检验员code+name
                                            entry.setValue(user.getJobNum()+user.getFullname());
                                        }
                                    }

                                }*/
                                  /*  if(OPERATOR.equals((String) entry.getKey())) {
                                        User user = iUserDao.selectByPk((String) entry.getValue());
                                        //设置操作员name
                                        entry.setValue(user.getFullname());
                                    }*/
                                if(WORK_TIME_CODE.equals((String) entry.getKey())) {
                                    if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                        WorkTimeVo workTimeVo = workTimeMapper.selectByPk((String) entry.getValue());
                                        if(!StringUtils.isEmpty(workTimeVo)) {
                                            //设置工时code+name
                                            entry.setValue(String.valueOf(workTimeVo.getWorkTimeCode()+"-"+workTimeVo.getWorkTime()));
                                        }
                                    }

                                }
                                if(OPERATOR.equals((String) entry.getKey())) {
                                    if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                        if (String.valueOf(entry.getValue()).contains("、")){
                                            String[] splits = String.valueOf(entry.getValue()).split("、");
                                            for (int j = 0; j < splits.length; j++) {
                                                User user = iUserDao.selectByJobNum(splits[j]);
                                                if (j == 0){
                                                    operator.append(splits[j]+user.getFullname());
                                                }else {
                                                    operator.append("、").append(splits[j]+user.getFullname());
                                                }
                                            }
                                        }else {
                                            User user = iUserDao.selectByJobNum(String.valueOf(entry.getValue()));
                                            operator.append(String.valueOf(entry.getValue())+user.getFullname());
                                        }
                                        if(!StringUtils.isEmpty(operator)) {
                                            //设置工时code+name
                                            entry.setValue(operator);
                                        }
                                    }
                                }

                                if(CREATOR.equals((String) entry.getKey())) {
                                    if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                        User user = iUserDao.selectByJobNum((String) entry.getValue());
                                        if(!StringUtils.isEmpty(user)) {
                                            //设置工时code+name
                                            entry.setValue((String) entry.getValue()+user.getFullname());
                                        }
                                    }
                                }
                 /*               if(CREATOR.equals((String) entry.getKey())) {
                                    if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                        User user = iUserDao.selectByPk((String) entry.getValue());
                                        if(!StringUtils.isEmpty(user)) {
                                            //设置创建者code+name
                                            entry.setValue(user.getJobNum()+user.getFullname());
                                        }
                                    }

                                }
                                if(MODIFIER.equals((String) entry.getKey())) {
                                    if(!StringUtils.isEmpty((String) entry.getValue())&&!" ".equals((String) entry.getValue())) {
                                        User user = iUserDao.selectByPk((String) entry.getValue());
                                        if(!StringUtils.isEmpty(user)) {
                                            //设置修改者code+name
                                            entry.setValue(user.getJobNum()+user.getFullname());
                                        }
                                    }

                                }*/
                                //zww 公式赋值开始
                                //赋初始值 即无公式时取默认值
                                String formulaValue = null;
                                if (!StringUtils.isEmpty(entry.getValue())) {
                                    formulaValue = entry.getValue().toString();
                                }
                                try {
                                    //获取公式
                                    String formula = incomePartJudgeFieldMapper.selectFormulaByEnFieldName((String) entry.getKey());
                                    //获取公式计算值
                                    if (!StringUtils.isEmpty(formula) && !StringUtils.isEmpty(id)) {
                                        //有公式取公式值
                                        if (!StringUtils.isEmpty(FormulaUtils.calculation(formula, id))) {
                                            formulaValue = FormulaUtils.calculation(formula, id);
                                        }
                                    }
                                }
                                catch (Exception e) {
                                    //事务手动回滚
                                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                    //遇到异常，返回异常原因
                                    e.printStackTrace();
                                    return ResponseTemplate.builder().code(1).message("请检查公式中对应的科目号类型是否符合运算条件,如名称不可加减乘除").count(0l).build();
                                }
                                    //zww 公式赋值结束

                                linkedHashMap.put(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, (String) entry.getKey()), formulaValue);
                            }
                            //重置将key驼峰
                            secondList.set(i, linkedHashMap);

                        }
                    }
                    //构造分页实体
                    PageInfo<LinkedHashMap> info = new PageInfo<>(secondList);
                    map.put("secondList", secondList);
                    if (info.getTotal() > 0) {
                        //查询到数据
                        return ResponseTemplate.builder().code(0).message("查询成功").count((long) info.getTotal()).data(map).build();
                    } else {
                        //没有查询到数据
                        return ResponseTemplate.builder().code(1).message("没有查到对应数据").count((long) info.getTotal()).data(map).build();
                    }



                } else {
                    return ResponseTemplate.builder().code(1).message("来料接收与判定字段均未启用").count(0l).build();
                }
            } catch (Exception e) {
                //事务手动回滚
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                //遇到异常，返回异常原因
                e.printStackTrace();
                return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
            }
        } else {
            return ResponseTemplate.builder().code(1).message("分页参数错误").count(0l).build();
        }
    }

    /**
     * 查询所有数据  不进行分页
     * @return
     */
    @Override
    public ResponseTemplate selectAllDataTwo() {
        return null;
    }


    public void log(String str) {
        System.out.println("=====================>" + str + "=====================>");
    }

    /**
     *@Description: excel数据导入
     *@Param: [file]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/26
     */
    @Override
    public ResponseTemplate getExcelImport(String idName ,String file) {
        try {
            lock.lock();
            //获取excel数据
            List<List<String>> excelData = ExcelUtil.getData(file);
            if (excelData.size() == 1 && excelData.get(0).size() == 1){
                //错误信息
                String errorInfo = excelData.get(0).get(0);
                return ResponseTemplate.builder().code(1).message(errorInfo).count(0l).build();
            }
            //获取表头
            List<String> headerList = excelData.get(0);

            //记录重复个数
            int count = 0;
            //记录订单重复数
            List<String> repeOrderNumber = new ArrayList<>();

            if (headerList.contains(UNIT_PRICE_INCLUDE_TAX)){
                List<String> list = new ArrayList<>();
                //遍历表头，去空格
                for (String str:headerList){
                    //表头
                    list.add(StringReplacUtils.replaceBlank(str));
                }
                //抛去表头，从第二行开始
                for (int i = 1 ; i < excelData.size();i++ ){
                    //数据
                    List<String> listData = excelData.get(i);
                    //主表实体
                    IncomePartJudgeVo incomePartJudgeVo = new IncomePartJudgeVo();
                    //序
                    int id = getIncomePartJudgeId();
                    incomePartJudgeVo.setId(id);

                    //获取订单号下标
                    int orderNumberIndex = 0 ;
                    if (list.contains(ORDERNUMBER)){
                        orderNumberIndex = list.indexOf(ORDERNUMBER);
                    }
                    //获取来件单位下标
                    int incomePartUnitIndex = 0 ;
                    if (list.contains(INCOMEPARTUNIT)){
                        incomePartUnitIndex = list.indexOf(INCOMEPARTUNIT);
                    }
                    //获取工种下标
                    int typeWorkIndex = 0 ;
                    if (list.contains(TYPEWORK)){
                        typeWorkIndex = list.indexOf(TYPEWORK);
                    }
                    //获取图号下标
                    int drawNoIndex = 0 ;
                    if (list.contains(DRAWNO)){
                        drawNoIndex = list.indexOf(DRAWNO);
                    }
                    //获取来件数量下标
                    int incomePartQuantityIndex = 0 ;
                    if (list.contains(INCOME_PART_QUANTITY)){
                        incomePartQuantityIndex = list.indexOf(INCOME_PART_QUANTITY);
                    }
                    //获取来件时间下标
                    int incomePartTimeIndex = 0 ;
                    if (list.contains(INCOME_PART_TIME)){
                        incomePartTimeIndex = list.indexOf(INCOME_PART_TIME);
                    }

                    //根据订单号查数据
//                    IncomePartJudgeVo incomePartJudgeVoOrderNum = incomePartJudgeMapper.selectByOrderNumber(listData.get(orderNumberIndex));
//                    //判断是否为空
//                    if (!StringUtils.isEmpty(incomePartJudgeVoOrderNum)){
//                        if (listData.get(drawNoIndex).equals(incomePartJudgeVoOrderNum.getDrawNoCode()) && listData.get(typeWorkIndex).equals(incomePartJudgeVoOrderNum.getTypeWorkCode())
//                        && listData.get(incomePartUnitIndex).equals(incomePartJudgeVoOrderNum.getIncomePartUnitCode()) && listData.get(incomePartQuantityIndex).equals(incomePartJudgeVoOrderNum.getIncomePartQuantity())
//                        && listData.get(incomePartTimeIndex).equals(incomePartJudgeVoOrderNum.getIncomePartTime()) && listData.get(18).equals(incomePartJudgeVoOrderNum.getTimeCompletedOne())){
//                            continue;
//                        }
////                        incomePartJudgeVo.setId(incomePartJudgeVoOrderNum.getId());
////                        //删除数据库中的数据
////                        incomePartJudgeMapper.realDelete(incomePartJudgeVoOrderNum.getOrderNumber());
//                    }
                    int sameNum = 0;
                    List<IncomePartJudgeVo> incomePartJudgeVoByOrderNumbers = incomePartJudgeMapper.selectByOrderNumber(listData.get(orderNumberIndex));
                    for (IncomePartJudgeVo incomePartJudgeVoByOrderNumber:incomePartJudgeVoByOrderNumbers) {
                        if (!StringUtils.isEmpty(incomePartJudgeVoByOrderNumber)){
                            if (listData.get(drawNoIndex).equals(incomePartJudgeVoByOrderNumber.getDrawNoCode()) && listData.get(typeWorkIndex).equals(incomePartJudgeVoByOrderNumber.getTypeWorkCode())
                                    && listData.get(incomePartUnitIndex).equals(incomePartJudgeVoByOrderNumber.getIncomePartUnitCode()) && listData.get(incomePartQuantityIndex).equals(incomePartJudgeVoByOrderNumber.getIncomePartQuantity())
                                    && listData.get(incomePartTimeIndex).equals(incomePartJudgeVoByOrderNumber.getIncomePartTime()) && listData.get(18).equals(incomePartJudgeVoByOrderNumber.getTimeCompletedOne())){
                                sameNum++;
                            }
//                        incomePartJudgeVo.setId(incomePartJudgeVoByOrderNumber.getId());
//                        incomePartJudgeMapper.realDelete(incomePartJudgeVoByOrderNumber.getOrderNumber());
//                        //记录重复
//                        repeOrderNumber.add(incomePartJudgeVoByOrderNumber.getOrderNumber());
//                        count++;
                        }
                    }
                    if (sameNum>0){
                        continue;
                    }

                    //来件单位
                    IncomePartUnitVo incomePartUnitVo = new IncomePartUnitVo();

                    //查询来件单位是否存在
                    IncomePartUnitVo incomePartUnitVoByName = incomePartUnitMapper.selectByCnName(listData.get(incomePartUnitIndex));
                    if (!StringUtils.isEmpty(incomePartUnitVoByName)){
                        //存在
                        incomePartJudgeVo.setIncomePartUnitCode(incomePartUnitVoByName.getIncomepartunitCode());
                    }else{
                        //查询来件单位表中总数
                        int sum = incomePartUnitMapper.selectAmount();
                        //获取编号字母的字母下标
                        int letterGroup = sum/AMOUNT;
                        //获取编号数字
                        int numberGroup = sum%AMOUNT;
                        String str = null;
                        //字母数组
                        char[] letters = LETTER.toCharArray();
                        //判断表中数据为空时和编号数字在0到999之间
                        if ((letterGroup==0 && numberGroup ==0) || (numberGroup > 0 && numberGroup<AMOUNT)){
                            str = letters[letterGroup] + String.format("%03d", numberGroup+1);
                        }else {
                            str = letters[letterGroup+1] + String.format("%03d", 1);
                        }
                        //判断生成的编码是否存在
                        while(true){
                            IncomePartUnitVo incomePartUnitVoByCode = incomePartUnitMapper.selectByCode(str);
                            //存在跳过，继续生成
                            if (!StringUtils.isEmpty(incomePartUnitVoByCode)){
                                //字母
                                String startStr = null;
                                //数字
                                String endStr = null;
                                startStr = str.substring(0,1);
                                endStr = str.substring(1);
                                if (Integer.valueOf(endStr) == AMOUNT ){
                                    endStr = String.format("%03d", 1);
                                    if (startStr.equals(letters[letterGroup])){
                                        startStr = String.valueOf(letters[letterGroup+1]);
                                    }else {
                                        startStr = String.valueOf(letters[letterGroup+2]);
                                    }
                                    str = startStr + endStr;
                                }else {
                                    endStr = String.format("%03d", Integer.valueOf(endStr)+1);
                                    str = startStr + endStr;
                                }
                            } else {
                                break;
                            }
                        }
                        //设置来件单位编码
                        incomePartUnitVo.setIncomepartunitCode(str);
                        if (!StringUtils.isEmpty(listData.get(incomePartUnitIndex))){
                            incomePartUnitVo.setCnName(listData.get(incomePartUnitIndex));
                        }
                        //存入来件单位表
                        incomePartUnitMapper.insert(incomePartUnitVo);
                        //设置来件单位编码
                        incomePartJudgeVo.setIncomePartUnitCode(str);
                    }

                    //工种实体
                    TypeWorkVo typeWorkVo = new TypeWorkVo();


                    //查询工种是否存在
                    TypeWorkVo typeWorkVoByName = typeWorkMapper.selectByName(listData.get(typeWorkIndex));
                    if (!StringUtils.isEmpty(typeWorkVoByName)) {
                        //存在
                        incomePartJudgeVo.setTypeWorkCode(typeWorkVoByName.getTypeworkCode());
                    }else {
                        //查询工种表中总数
                        int sum = typeWorkMapper.selectAmount();
                        //获取编号字母的字母下标
                        int letterGroup = sum/AMOUNT;
                        //获取编号数字
                        int numberGroup = sum%AMOUNT;
                        String str = null;
                        //字母数组
                        char[] letters = LETTER.toCharArray();
                        //判断表中数据为空时和编号数字在0到999之间
                        if ((letterGroup==0 && numberGroup ==0) || (numberGroup > 0 && numberGroup<AMOUNT)){
                            str = letters[letterGroup] + String.format("%03d", numberGroup+1);
                        }else {
                            str = letters[letterGroup+1] + String.format("%03d", 1);
                        }
                        //判断生成的编码是否存在
                        while(true){
                            TypeWorkVo typeWorkVoByCode = typeWorkMapper.selectByCode(str);
                            //存在跳过，继续生成
                            if (!StringUtils.isEmpty(typeWorkVoByCode)){
                                //字母
                                String startStr = null;
                                //数字
                                String endStr = null;
                                startStr = str.substring(0,1);
                                endStr = str.substring(1);
                                if (Integer.valueOf(endStr) == AMOUNT ){
                                    endStr = String.format("%03d", 1);
                                    if (startStr.equals(letters[letterGroup])){
                                        startStr = String.valueOf(letters[letterGroup+1]);
                                    }else {
                                        startStr = String.valueOf(letters[letterGroup+2]);
                                    }
                                    str = startStr + endStr;
                                }else {
                                    endStr = String.format("%03d", Integer.valueOf(endStr)+1);
                                    str = startStr + endStr;
                                }
                            } else {
                                break;
                            }
                        }

                        typeWorkVo.setTypeworkCode(str);
                        if (!StringUtils.isEmpty(listData.get(typeWorkIndex))) {
                            typeWorkVo.setName(listData.get(typeWorkIndex));
                        }
                        //存入工种表
                        typeWorkMapper.insert(typeWorkVo);
                        //设置工种编码
                        incomePartJudgeVo.setTypeWorkCode(str);
                    }

                    //图号实体
                    DrawNoVo drawNoVo = new DrawNoVo();


                    //获取型号下标
                    int modelNumberIndex = 0 ;
                    if (list.contains(MODEL_NUMBER)){
                        modelNumberIndex = list.indexOf(MODEL_NUMBER);
                    }

                    //获取型别下标
                    int modelTypeIndex = 0 ;
                    if (list.contains(MODEL_TYPE)){
                        modelTypeIndex = list.indexOf(MODEL_TYPE);
                    }
                    //获取零件名称下标
                    int partNameIndex = 0 ;
                    if (list.contains(PART_NAME)){
                        partNameIndex = list.indexOf(PART_NAME);
                    }
                    //获取热表序下标
                    int heatSurfaceSequenceIndex = 0 ;
                    if (list.contains(HEAT_SURFACE_SEQUENCE)){
                        heatSurfaceSequenceIndex = list.indexOf(HEAT_SURFACE_SEQUENCE);
                    }
                    //查询图号是否存在
                    DrawNoVo drawNoVoByName = drawNoMapper.selectByName(listData.get(drawNoIndex));
                    if (!StringUtils.isEmpty(drawNoVoByName)) {
                        //存在
                        incomePartJudgeVo.setDrawNoCode(drawNoVoByName.getDrawNoCode());
                    }else {
                        //查询图号表中总数
                        int sum = drawNoMapper.selectAmount();
                        //获取编号字母的字母下标
                        int letterGroup = sum/AMOUNT;
                        //获取编号数字
                        int numberGroup = sum%AMOUNT;
                        String str = null;
                        //字母数组
                        char[] letters = LETTER.toCharArray();
                        //判断表中数据为空时和编号数字在0到999之间
                        if ((letterGroup==0 && numberGroup ==0) || (numberGroup > 0 && numberGroup<AMOUNT)){
                            str = letters[letterGroup] + String.format("%03d", numberGroup+1);
                        }else {
                            str = letters[letterGroup+1] + String.format("%03d", 1);
                        }
                        //判断生成的编码是否存在
                        while(true){
                            DrawNoVo drawNoVoByCode = drawNoMapper.selectByCode(str);
                            //存在跳过，继续生成
                            if (!StringUtils.isEmpty(drawNoVoByCode)){
                                //字母
                                String startStr = null;
                                //数字
                                String endStr = null;
                                startStr = str.substring(0,1);
                                endStr = str.substring(1);
                                if (Integer.valueOf(endStr) == AMOUNT ){
                                    endStr = String.format("%03d", 1);
                                    if (startStr.equals(letters[letterGroup])){
                                        startStr = String.valueOf(letters[letterGroup+1]);
                                    }else {
                                        startStr = String.valueOf(letters[letterGroup+2]);
                                    }
                                    str = startStr + endStr;
                                }else {
                                    endStr = String.format("%03d", Integer.valueOf(endStr)+1);
                                    str = startStr + endStr;
                                }
                            } else {
                                break;
                            }
                        }

                        drawNoVo.setDrawNoCode(str);
                        drawNoVo.setIncomePartUnitCode(incomePartJudgeVo.getIncomePartUnitCode());
                        drawNoVo.setTypeWorkCode(incomePartJudgeVo.getTypeWorkCode());
                        if(!StringUtils.isEmpty(listData.get(drawNoIndex))){
                            drawNoVo.setName(listData.get(drawNoIndex));
                        }

                        drawNoVo.setModelNumber(listData.get(modelNumberIndex));

                        drawNoVo.setModelType(listData.get(modelTypeIndex));

                        drawNoVo.setPartName(listData.get(partNameIndex));
                        //获取含税单价下标
//                    int unitPriceIncludeTaxIndex = 0 ;
//                    if (list.contains(UNIT_PRICE_INCLUDE_TAX)){
//                        unitPriceIncludeTaxIndex = list.indexOf(UNIT_PRICE_INCLUDE_TAX);
//                    }

                        drawNoVo.setHeatSurfaceSequence(listData.get(heatSurfaceSequenceIndex));
                        //存入图号表
                        drawNoMapper.insert(drawNoVo);
                        //设置图号编码
                        incomePartJudgeVo.setDrawNoCode(str);


                    }
                    //型号
                    incomePartJudgeVo.setModelNumber(listData.get(modelNumberIndex));
                    //型别
                    incomePartJudgeVo.setModelType(listData.get(modelTypeIndex));
                    //零件名称
                    incomePartJudgeVo.setPartName(listData.get(partNameIndex));
                    //热表序
                    incomePartJudgeVo.setHeatSurfaceSequence(listData.get(heatSurfaceSequenceIndex));

                    //工时实体
                    WorkTimeVo workTimeVo = new WorkTimeVo();

                    //获取工时下标
                    int workTimeIndex = 0 ;
                    if (list.contains(WORK_TIME)){
                        workTimeIndex = list.indexOf(WORK_TIME);
                    }
                    //查询工时是否存在
                    WorkTimeVo workTimeVoByDrawNoTypeWork = workTimeMapper.selectByDrawNoTypeWork(incomePartJudgeVo.getDrawNoCode(),incomePartJudgeVo.getTypeWorkCode());
                    if (!StringUtils.isEmpty(workTimeVoByDrawNoTypeWork)) {
                        //存在
                        incomePartJudgeVo.setWorkTimeCode(workTimeVoByDrawNoTypeWork.getWorkTimeCode());
                    }else {
                        //查询工种表中总数
                        int sum = workTimeMapper.selectAmount();
                        //获取编号字母的字母下标
                        int letterGroup = sum/AMOUNT;
                        //获取编号数字
                        int numberGroup = sum%AMOUNT;
                        String str = null;
                        //字母数组
                        char[] letters = LETTER.toCharArray();
                        //判断表中数据为空时和编号数字在0到999之间
                        if ((letterGroup==0 && numberGroup ==0) || (numberGroup > 0 && numberGroup<AMOUNT)){
                            str = letters[letterGroup] + String.format("%03d", numberGroup+1);
                        }else {
                            str = letters[letterGroup+1] + String.format("%03d", 1);
                        }
                        //判断生成的编码是否存在
                        while(true){
                            WorkTimeVo workTimeVoByCode = workTimeMapper.selectByCode(str);
                            //存在跳过，继续生成
                            if (!StringUtils.isEmpty(workTimeVoByCode)){
                                //字母
                                String startStr = null;
                                //数字
                                String endStr = null;
                                startStr = str.substring(0,1);
                                endStr = str.substring(1);
                                if (Integer.valueOf(endStr) == AMOUNT ){
                                    endStr = String.format("%03d", 1);
                                    if (startStr.equals(letters[letterGroup])){
                                        startStr = String.valueOf(letters[letterGroup+1]);
                                    }else {
                                        startStr = String.valueOf(letters[letterGroup+2]);
                                    }
                                    str = startStr + endStr;
                                }else {
                                    endStr = String.format("%03d", Integer.valueOf(endStr)+1);
                                    str = startStr + endStr;
                                }
                            } else {
                                break;
                            }
                        }

                        workTimeVo.setWorkTimeCode(str);
                        workTimeVo.setDrawNoCode(incomePartJudgeVo.getDrawNoCode());
                        workTimeVo.setTypeWorkCode(incomePartJudgeVo.getTypeWorkCode());
                        if (!StringUtils.isEmpty(listData.get(workTimeIndex))){
                            workTimeVo.setWorkTime(String.valueOf(listData.get(workTimeIndex)));
                        }
                        workTimeMapper.insert(workTimeVo);

                        //工时编码
                        incomePartJudgeVo.setWorkTimeCode(str);
                    }

                    //工作分配实体
                    AssignJobVo assignJobVo = new AssignJobVo();

                    //获取工作分配下标
                    int assignJobIndex = 0 ;
                    if (list.contains(OPERATOR_USER)){
                        assignJobIndex = list.indexOf(OPERATOR_USER);
                    }
                    String operators = listData.get(assignJobIndex);
                    if (operators.contains("、")){
                        String[] operatorlists = operators.split("、");
                        incomePartJudgeVo.setOperator(operators);
                    }

                    //查询工作分配是否存在
                    AssignJobVo assignJobVoByDrawNoCode = assignJobMapper.selectByDrawNoCode(incomePartJudgeVo.getDrawNoCode());
                    if (!StringUtils.isEmpty(assignJobVoByDrawNoCode)) {
                        //存在
                        incomePartJudgeVo.setOperator(assignJobVoByDrawNoCode.getOperatorOne());
                    }else {
                        //查询工种表中总数
                        int sum = assignJobMapper.selectAmount();
                        //获取编号字母的字母下标
                        int letterGroup = sum/AMOUNT;
                        //获取编号数字
                        int numberGroup = sum%AMOUNT;
                        String str = null;
                        //字母数组
                        char[] letters = LETTER.toCharArray();
                        //判断表中数据为空时和编号数字在0到999之间
                        if ((letterGroup==0 && numberGroup ==0) || (numberGroup > 0 && numberGroup<AMOUNT)){
                            str = letters[letterGroup] + String.format("%03d", numberGroup+1);
                        }else {
                            str = letters[letterGroup+1] + String.format("%03d", 1);
                        }

                        //判断生成的编码是否存在
                        while(true){
                            AssignJobVo assignJobVoByCode = assignJobMapper.selectByCode(str);
                            //存在跳过，继续生成
                            if (!StringUtils.isEmpty(assignJobVoByCode)){
                                //字母
                                String startStr = null;
                                //数字
                                String endStr = null;
                                startStr = str.substring(0,1);
                                endStr = str.substring(1);
                                if (Integer.valueOf(endStr) == AMOUNT ){
                                    endStr = String.format("%03d", 1);
                                    if (startStr.equals(letters[letterGroup])){
                                        startStr = String.valueOf(letters[letterGroup+1]);
                                    }else {
                                        startStr = String.valueOf(letters[letterGroup+2]);
                                    }
                                    str = startStr + endStr;
                                }else {
                                    endStr = String.format("%03d", Integer.valueOf(endStr)+1);
                                    str = startStr + endStr;
                                }
                            } else {
                                break;
                            }
                        }

                        assignJobVo.setAssignjobCode(str);
                        assignJobVo.setDrawNoCode(incomePartJudgeVo.getDrawNoCode());
                        if (!StringUtils.isEmpty(listData.get(assignJobIndex))){
                            assignJobVo.setOperatorOne(listData.get(assignJobIndex));
                        }
                        //assignJobMapper.insert(assignJobVo);
                        //操作人
                        incomePartJudgeVo.setOperator(listData.get(assignJobIndex));
                    }

                    //订单号
                    incomePartJudgeVo.setOrderNumber(listData.get(8));
                    //来件数量
                    if (!StringUtils.isEmpty(listData.get(9))) {
                        incomePartJudgeVo.setIncomePartQuantity(listData.get(9));
                    }
                    //外委
                    incomePartJudgeVo.setOutsource(listData.get(10));
                    //来件时间
                    if (!StringUtils.isEmpty(listData.get(11))) {
                        incomePartJudgeVo.setIncomePartTime(listData.get(11));
                    }
                    //紧急程度
                    incomePartJudgeVo.setDegreeUrgency(listData.get(12));
                    //需求时间
                    if (!StringUtils.isEmpty(listData.get(13))) {
                        incomePartJudgeVo.setDemandTime(listData.get(13));
                    }
                    //备注
                    incomePartJudgeVo.setRemark(listData.get(14));
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(15))) {
                        incomePartJudgeVo.setQuantityCompleted(listData.get(15));
                    }
                    //未完成数量
                    if (!StringUtils.isEmpty(listData.get(16))) {
                        incomePartJudgeVo.setUnfinishedQuantity(listData.get(16));
                    }
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(17))) {
                        incomePartJudgeVo.setQuantityCompletedOne(listData.get(17));
                    }
                    //完成时间
                    if (!StringUtils.isEmpty(listData.get(18))) {
                        incomePartJudgeVo.setTimeCompletedOne(listData.get(18));
                    }
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(19))) {
                        incomePartJudgeVo.setQuantityCompletedTwo(listData.get(19));
                    }
                    //完成时间
                    if (!StringUtils.isEmpty(listData.get(20))) {
                        incomePartJudgeVo.setTimeCompletedTwo(listData.get(20));
                    }
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(21))) {
                        incomePartJudgeVo.setQuantityCompletedThree(listData.get(21));
                    }
                    //完成时间
                    if (!StringUtils.isEmpty(listData.get(22))) {
                        incomePartJudgeVo.setTimeCompletedThree(listData.get(22));
                    }
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(23))) {
                        incomePartJudgeVo.setQuantityCompletedFour(listData.get(23));
                    }
                    //完成时间
                    if (!StringUtils.isEmpty(listData.get(24))) {
                        incomePartJudgeVo.setTimeCompletedFour(listData.get(24));
                    }
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(25))) {
                        incomePartJudgeVo.setQuantityCompletedFive(listData.get(25));
                    }
                    //完成时间
                    if (!StringUtils.isEmpty(listData.get(26))) {
                        incomePartJudgeVo.setTimeCompletedFive(listData.get(26));
                    }
                    //报废数量
                    if (!StringUtils.isEmpty(listData.get(27))) {
                        incomePartJudgeVo.setScrapQuantity(listData.get(27));
                    }
                    //报废单号
                    incomePartJudgeVo.setScrapOrderNumber(listData.get(28));
                    //完成率
                    incomePartJudgeVo.setCompletionRate(listData.get(29));

                    //去向
                    incomePartJudgeVo.setWhereabouts(listData.get(31));
                    //停留时间
                    if (!StringUtils.isEmpty(listData.get(32))) {
                        incomePartJudgeVo.setResidenceTime(listData.get(32));
                    }
                    //来件验收结果
                    incomePartJudgeVo.setIncomePartJudgeResult(listData.get(33));
                    //检验员
                    incomePartJudgeVo.setInspector(listData.get(34));
                    //图号+工种
                    incomePartJudgeVo.setDrawnoAddTypework(listData.get(35));
                    //含税单价
                    if (!StringUtils.isEmpty(listData.get(36))) {
                        incomePartJudgeVo.setUnitPriceIncludeTax(listData.get(36));
                    }
                    //含税总价
                    if (!StringUtils.isEmpty(listData.get(37))) {
                        incomePartJudgeVo.setTotalPriceIncludeTax(listData.get(37));
                    }

                    //总工时
                    incomePartJudgeVo.setTotalWorkTime(listData.get(39));
                    //断路器产品
                    incomePartJudgeVo.setCircuitBreakerProduct(listData.get(40));
                    //创建人
                    User user = iUserDao.selectByPk(idName);
                    incomePartJudgeVo.setCreator(user.getJobNum());
                    Date date = new Date();//获取当前的日期
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
                    String strDate = df.format(date);//获取String类型的时间
                    incomePartJudgeVo.setCreateTime(strDate);

                    incomePartJudgeMapper.importInsert(incomePartJudgeVo);
                }
            }else {
                List<String> list = new ArrayList<>();
                for (String str:headerList){
                    //表头
                    list.add(StringReplacUtils.replaceBlank(str));
                }
                //抛去表头，从第二行开始
                for (int i = 1 ; i < excelData.size();i++ ){
                    List<String> listData = excelData.get(i);
                    //获取订单号下标
                    int orderNumberIndex = 0 ;
                    if (list.contains(ORDERNUMBER)){ orderNumberIndex = list.indexOf(ORDERNUMBER); }
                    //获取来件单位下标
                    int incomePartUnitIndex = 0 ;
                    if (list.contains(INCOMEPARTUNIT)){ incomePartUnitIndex = list.indexOf(INCOMEPARTUNIT); }
                    //获取工种下标
                    int typeWorkIndex = 0 ;
                    if (list.contains(TYPEWORK)){ typeWorkIndex = list.indexOf(TYPEWORK); }
                    //获取图号下标
                    int drawNoIndex = 0 ;
                    if (list.contains(DRAWNO)){ drawNoIndex = list.indexOf(DRAWNO); }
                    //获取来件数量下标
                    int incomePartQuantityIndex = 0 ;
                    if (list.contains(INCOME_PART_QUANTITY)){ incomePartQuantityIndex = list.indexOf(INCOME_PART_QUANTITY); }
                    //获取来件时间下标
                    int incomePartTimeIndex = 0 ;
                    if (list.contains(INCOME_PART_TIME)){ incomePartTimeIndex = list.indexOf(INCOME_PART_TIME); }
                    //获取型号下标
                    int modelNumberIndex = 0 ;
                    if (list.contains(MODEL_NUMBER)){ modelNumberIndex = list.indexOf(MODEL_NUMBER); }
                    //获取型别下标
                    int modelTypeIndex = 0 ;
                    if (list.contains(MODEL_TYPE)){ modelTypeIndex = list.indexOf(MODEL_TYPE); }
                    //获取零件名称下标
                    int partNameIndex = 0 ;
                    if (list.contains(PART_NAME)){ partNameIndex = list.indexOf(PART_NAME); }
                    //获取热表序下标
                    int heatSurfaceSequenceIndex = 0 ;
                    if (list.contains(HEAT_SURFACE_SEQUENCE)){ heatSurfaceSequenceIndex = list.indexOf(HEAT_SURFACE_SEQUENCE); }
                    //获取操作人下标
                    int assignJobIndex = 0 ;
                    if (list.contains(OPERATOR_USER)){ assignJobIndex = list.indexOf(OPERATOR_USER); }
                    //主表实体
                    IncomePartJudgeVo incomePartJudgeVo = new IncomePartJudgeVo();
                    //序
                    int id = getIncomePartJudgeId();
                    incomePartJudgeVo.setId(id);
                    //判断excel中数据与数据库数据相同的字段数
                    int sameNum = 0;
                    //判断订单号是否为空
                    if (StringUtils.isEmpty(listData.get(orderNumberIndex))){
                        continue;
                    }
                    //根据订单号查询数据库中的数据
                    List<IncomePartJudgeVo> incomePartJudgeVoByOrderNumbers = incomePartJudgeMapper.selectByOrderNumber(listData.get(orderNumberIndex));
                    for (IncomePartJudgeVo incomePartJudgeVoByOrderNumber:incomePartJudgeVoByOrderNumbers) {
                        sameNum = 0;
                        if (!StringUtils.isEmpty(incomePartJudgeVoByOrderNumber)) {
                            //图号
                            if (!StringUtils.isEmpty(listData.get(drawNoIndex)) && !StringUtils.isEmpty(listData.get(drawNoIndex).trim())) {
                                if (listData.get(drawNoIndex).trim().equals(incomePartJudgeVoByOrderNumber.getDrawNoCode())) {
                                    sameNum++;
                                }
                            } else {
                                if (incomePartJudgeVoByOrderNumber.getDrawNoCode() == null) {
                                    sameNum++;
                                }
                            }
                            //零件名称
                            if (!StringUtils.isEmpty(listData.get(partNameIndex)) && !StringUtils.isEmpty(listData.get(partNameIndex).trim())) {
                                if (listData.get(partNameIndex).equals(incomePartJudgeVoByOrderNumber.getPartName())) {
                                    sameNum++;
                                }
                            } else {
                                if (incomePartJudgeVoByOrderNumber.getPartName() == null) {
                                    sameNum++;
                                }
                            }
                            //工种
                            if (!StringUtils.isEmpty(listData.get(typeWorkIndex)) && !StringUtils.isEmpty(listData.get(typeWorkIndex).trim())) {
                                if (listData.get(typeWorkIndex).trim().equals(incomePartJudgeVoByOrderNumber.getTypeWorkCode())) {
                                    sameNum++;
                                }
                            } else {
                                if (incomePartJudgeVoByOrderNumber.getTypeWorkCode() == null) {
                                    sameNum++;
                                }
                            }
                            //来件单位
                            if (!StringUtils.isEmpty(listData.get(incomePartUnitIndex)) && !StringUtils.isEmpty(listData.get(incomePartUnitIndex).trim())) {
                                if (listData.get(incomePartUnitIndex).trim().equals(incomePartJudgeVoByOrderNumber.getIncomePartUnitCode())) {
                                    sameNum++;
                                }
                            } else {
                                if (incomePartJudgeVoByOrderNumber.getIncomePartUnitCode() == null) {
                                    sameNum++;
                                }
                            }
                            //来件数量
                            if (!StringUtils.isEmpty(listData.get(incomePartQuantityIndex)) && !StringUtils.isEmpty(listData.get(incomePartQuantityIndex).trim())) {
                                if (listData.get(incomePartQuantityIndex).trim().equals(incomePartJudgeVoByOrderNumber.getIncomePartQuantity())) {
                                    sameNum++;
                                }
                            } else {
                                if (incomePartJudgeVoByOrderNumber.getIncomePartQuantity() == null) {
                                    sameNum++;
                                }
                            }
                            //来件时间
                            if (!StringUtils.isEmpty(listData.get(incomePartTimeIndex)) && !StringUtils.isEmpty(listData.get(incomePartTimeIndex).trim())) {
                                if (listData.get(incomePartTimeIndex).trim().equals(incomePartJudgeVoByOrderNumber.getIncomePartTime())) {
                                    sameNum++;
                                }
                            } else {
                                if (incomePartJudgeVoByOrderNumber.getIncomePartTime() == null) {
                                    sameNum++;
                                }
                            }
                            //完成数量
                            if (!StringUtils.isEmpty(listData.get(15)) && !StringUtils.isEmpty(listData.get(15).trim())) {
                                if (listData.get(15).trim().equals(incomePartJudgeVoByOrderNumber.getQuantityCompleted())) {
                                    sameNum++;
                                }
                            } else {
                                if (incomePartJudgeVoByOrderNumber.getQuantityCompleted() == null) {
                                    sameNum++;
                                }
                            }
                            //完成时间
                            if (!StringUtils.isEmpty(listData.get(18)) && !StringUtils.isEmpty(listData.get(18).trim())) {
                                if (listData.get(18).trim().equals(incomePartJudgeVoByOrderNumber.getTimeCompletedOne())) {
                                    sameNum++;
                                }
                            } else {
                                if (incomePartJudgeVoByOrderNumber.getTimeCompletedOne() == null) {
                                    sameNum++;
                                }
                            }

                        }
                        //判断条件完全相同，退出循环
                        if (sameNum == 8){
                            //记录相同订单号
                            repeOrderNumber.add(incomePartJudgeVoByOrderNumber.getOrderNumber());
                            break;
                        }
                    }
                    //判断数据相同，此条数据不录入
                    if (sameNum == 8){
                        //记录相同条数
                        count++;
                        continue;
                    }
                    //================================================================
                    if(!StringUtils.isEmpty(listData.get(incomePartUnitIndex))){
                        if(!StringUtils.isEmpty(listData.get(incomePartUnitIndex).trim())){
                            //来件单位
                            IncomePartUnitVo incomePartUnitVo = new IncomePartUnitVo();
                            //查询来件单位是否存在
                            IncomePartUnitVo incomePartUnitVoByCnName = incomePartUnitMapper.selectByCnName(listData.get(incomePartUnitIndex).trim());
                            if (!StringUtils.isEmpty(incomePartUnitVoByCnName)){
                                //存在
                                incomePartJudgeVo.setIncomePartUnitCode(incomePartUnitVoByCnName.getIncomepartunitCode());
                            }else{
                                //查询来件单位表中总数
                                int sum = incomePartUnitMapper.selectAmount();
                                //获取编号字母的字母下标
                                int letterGroup = sum/AMOUNT;
                                //获取编号数字
                                int numberGroup = sum%AMOUNT;
                                String str = null;
                                //字母数组
                                char[] letters = LETTER.toCharArray();
                                //判断表中数据为空时和编号数字在0到999之间
                                if ((letterGroup==0 && numberGroup ==0) || (numberGroup > 0 && numberGroup<AMOUNT)){
                                    str = letters[letterGroup] + String.format("%03d", numberGroup+1);
                                }else {
                                    str = letters[letterGroup+1] + String.format("%03d", 1);
                                }
                                //判断生成的编码是否存在
                                while(true){
                                    IncomePartUnitVo incomePartUnitVoByCode = incomePartUnitMapper.selectByCode(str);
                                    //存在跳过，继续生成
                                    if (!StringUtils.isEmpty(incomePartUnitVoByCode)){
                                        //字母
                                        String startStr = null;
                                        //数字
                                        String endStr = null;
                                        startStr = str.substring(0,1);
                                        endStr = str.substring(1);
                                        if (Integer.valueOf(endStr) == AMOUNT ){
                                            endStr = String.format("%03d", 1);
                                            if (startStr.equals(letters[letterGroup])){
                                                startStr = String.valueOf(letters[letterGroup+1]);
                                            }else {
                                                startStr = String.valueOf(letters[letterGroup+2]);
                                            }
                                            str = startStr + endStr;
                                        }else {
                                            endStr = String.format("%03d", Integer.valueOf(endStr)+1);
                                            str = startStr + endStr;
                                        }
                                    } else {
                                        break;
                                    }
                                }
                                incomePartUnitVo.setIncomepartunitCode(str);
                                incomePartUnitVo.setCnName(listData.get(incomePartUnitIndex).trim());
                                //存入来件单位表
                                incomePartUnitMapper.insert(incomePartUnitVo);
                                //设置来件单位编码
                                incomePartJudgeVo.setIncomePartUnitCode(str);
                            }
                        }else {
                            incomePartJudgeVo.setIncomePartUnitCode(listData.get(incomePartUnitIndex).trim());
                        }
                    }else {
                        incomePartJudgeVo.setIncomePartUnitCode(listData.get(incomePartUnitIndex));
                    }

                    //================================================================
                    if (!StringUtils.isEmpty(listData.get(typeWorkIndex))){
                        if (!StringUtils.isEmpty(listData.get(typeWorkIndex).trim())){
                            //工种实体
                            TypeWorkVo typeWorkVo = new TypeWorkVo();
                            //查询工种是否存在
                            TypeWorkVo typeWorkVoByName = typeWorkMapper.selectByName(listData.get(typeWorkIndex).trim());
                            if (!StringUtils.isEmpty(typeWorkVoByName)) {
                                //存在
                                incomePartJudgeVo.setTypeWorkCode(typeWorkVoByName.getTypeworkCode());
                            }else {
                                //查询工种表中总数
                                int sum = typeWorkMapper.selectAmount();
                                //获取编号字母的字母下标
                                int letterGroup = sum/AMOUNT;
                                //获取编号数字
                                int numberGroup = sum%AMOUNT;
                                String str = null;
                                //字母数组
                                char[] letters = LETTER.toCharArray();
                                //判断表中数据为空时和编号数字在0到999之间
                                if ((letterGroup==0 && numberGroup ==0) || (numberGroup > 0 && numberGroup<AMOUNT)){
                                    str = letters[letterGroup] + String.format("%03d", numberGroup+1);
                                }else {
                                    str = letters[letterGroup+1] + String.format("%03d", 1);
                                }
                                //判断生成的编码是否存在
                                while(true){
                                    TypeWorkVo typeWorkVoByCode = typeWorkMapper.selectByCode(str);
                                    //存在跳过，继续生成
                                    if (!StringUtils.isEmpty(typeWorkVoByCode)){
                                        //字母
                                        String startStr = null;
                                        //数字
                                        String endStr = null;
                                        startStr = str.substring(0,1);
                                        endStr = str.substring(1);
                                        if (Integer.valueOf(endStr) == AMOUNT ){
                                            endStr = String.format("%03d", 1);
                                            if (startStr.equals(letters[letterGroup])){
                                                startStr = String.valueOf(letters[letterGroup+1]);
                                            }else {
                                                startStr = String.valueOf(letters[letterGroup+2]);
                                            }
                                            str = startStr + endStr;
                                        }else {
                                            endStr = String.format("%03d", Integer.valueOf(endStr)+1);
                                            str = startStr + endStr;
                                        }
                                    } else {
                                        break;
                                    }
                                }
                                typeWorkVo.setTypeworkCode(str);
                                typeWorkVo.setName(listData.get(typeWorkIndex).trim());
                                //存入工种表
                                typeWorkMapper.insert(typeWorkVo);
                                //设置工种编码
                                incomePartJudgeVo.setTypeWorkCode(str);
                            }
                        }else {
                            incomePartJudgeVo.setTypeWorkCode(listData.get(typeWorkIndex).trim());
                        }
                    }else {
                        incomePartJudgeVo.setTypeWorkCode(listData.get(typeWorkIndex));
                    }

                    //================================================================
                    if (!StringUtils.isEmpty(listData.get(drawNoIndex))){
                        if (!StringUtils.isEmpty(listData.get(drawNoIndex).trim())){
                            //图号实体
                            DrawNoVo drawNoVo = new DrawNoVo();
                            //查询图号是否存在
                            DrawNoVo drawNoVoByName = drawNoMapper.selectByName(listData.get(drawNoIndex).trim());
                            if (!StringUtils.isEmpty(drawNoVoByName)) {
                                //存在
                                incomePartJudgeVo.setDrawNoCode(drawNoVoByName.getDrawNoCode());
                            }else {
                                //查询图号表中总数
                                int sum = drawNoMapper.selectAmount();
                                //获取编号字母的字母下标
                                int letterGroup = sum/AMOUNT;
                                //获取编号数字
                                int numberGroup = sum%AMOUNT;
                                String str = null;
                                //字母数组
                                char[] letters = LETTER.toCharArray();
                                //判断表中数据为空时和编号数字在0到999之间
                                if ((letterGroup==0 && numberGroup ==0) || (numberGroup > 0 && numberGroup<AMOUNT)){
                                    str = letters[letterGroup] + String.format("%03d", numberGroup+1);
                                }else {
                                    str = letters[letterGroup+1] + String.format("%03d", 1);
                                }
                                //判断生成的编码是否存在
                                while(true){
                                    DrawNoVo drawNoVoByCode = drawNoMapper.selectByCode(str);
                                    //存在跳过，继续生成
                                    if (!StringUtils.isEmpty(drawNoVoByCode)){
                                        //字母
                                        String startStr = null;
                                        //数字
                                        String endStr = null;
                                        startStr = str.substring(0,1);
                                        endStr = str.substring(1);
                                        if (Integer.valueOf(endStr) == AMOUNT ){
                                            endStr = String.format("%03d", 1);
                                            if (startStr.equals(letters[letterGroup])){
                                                startStr = String.valueOf(letters[letterGroup+1]);
                                            }else {
                                                startStr = String.valueOf(letters[letterGroup+2]);
                                            }
                                            str = startStr + endStr;
                                        }else {
                                            endStr = String.format("%03d", Integer.valueOf(endStr)+1);
                                            str = startStr + endStr;
                                        }
                                    } else {
                                        break;
                                    }
                                }
                                drawNoVo.setDrawNoCode(str);
                                drawNoVo.setIncomePartUnitCode(incomePartJudgeVo.getIncomePartUnitCode());
                                drawNoVo.setTypeWorkCode(incomePartJudgeVo.getTypeWorkCode());
                                drawNoVo.setModelNumber(listData.get(modelNumberIndex));
                                drawNoVo.setModelType(listData.get(modelTypeIndex));
                                drawNoVo.setPartName(listData.get(partNameIndex));
                                drawNoVo.setHeatSurfaceSequence(listData.get(heatSurfaceSequenceIndex));
                                drawNoVo.setName(listData.get(drawNoIndex).trim());
                                //存入图号表
                                drawNoMapper.insert(drawNoVo);
                                //设置图号编码
                                incomePartJudgeVo.setDrawNoCode(str);
                            }
                        }else {
                            incomePartJudgeVo.setDrawNoCode(listData.get(drawNoIndex).trim());
                        }
                    }else {
                        incomePartJudgeVo.setDrawNoCode(listData.get(drawNoIndex));
                    }

                    //================================================================
                    if (!StringUtils.isEmpty(listData.get(drawNoIndex)) && !StringUtils.isEmpty(listData.get(typeWorkIndex))){
                        if (!StringUtils.isEmpty(listData.get(drawNoIndex).trim()) && !StringUtils.isEmpty(listData.get(typeWorkIndex))){
                            //工时实体
                            WorkTimeVo workTimeVo = new WorkTimeVo();
                            //查询对应此图号工种的工时是否存在
                            WorkTimeVo workTimeVoByDrawNoTypeWork = workTimeMapper.selectByDrawNoTypeWork(incomePartJudgeVo.getDrawNoCode(),incomePartJudgeVo.getTypeWorkCode());
                            if (!StringUtils.isEmpty(workTimeVoByDrawNoTypeWork)) {
                                //存在
                                incomePartJudgeVo.setWorkTimeCode(workTimeVoByDrawNoTypeWork.getWorkTimeCode());
                            }else {
                                //查询工时表中总数
                                int sum = workTimeMapper.selectAmount();
                                //获取编号字母的字母下标
                                int letterGroup = sum/AMOUNT;
                                //获取编号数字
                                int numberGroup = sum%AMOUNT;
                                String str = null;
                                //字母数组
                                char[] letters = LETTER.toCharArray();
                                //判断表中数据为空时和编号数字在0到999之间
                                if ((letterGroup==0 && numberGroup ==0) || (numberGroup > 0 && numberGroup<AMOUNT)){
                                    str = letters[letterGroup] + String.format("%03d", numberGroup+1);
                                }else {
                                    str = letters[letterGroup+1] + String.format("%03d", 1);
                                }
                                //判断生成的编码是否存在
                                while(true){
                                    WorkTimeVo workTimeVoByCode = workTimeMapper.selectByCode(str);
                                    //存在跳过，继续生成
                                    if (!StringUtils.isEmpty(workTimeVoByCode)){
                                        //字母
                                        String startStr = null;
                                        //数字
                                        String endStr = null;
                                        startStr = str.substring(0,1);
                                        endStr = str.substring(1);
                                        if (Integer.valueOf(endStr) == AMOUNT ){
                                            endStr = String.format("%03d", 1);
                                            if (startStr.equals(letters[letterGroup])){
                                                startStr = String.valueOf(letters[letterGroup+1]);
                                            }else {
                                                startStr = String.valueOf(letters[letterGroup+2]);
                                            }
                                            str = startStr + endStr;
                                        }else {
                                            endStr = String.format("%03d", Integer.valueOf(endStr)+1);
                                            str = startStr + endStr;
                                        }
                                    } else {
                                        break;
                                    }
                                }
                                workTimeVo.setWorkTimeCode(str);
                                workTimeVo.setDrawNoCode(incomePartJudgeVo.getDrawNoCode());
                                workTimeVo.setTypeWorkCode(incomePartJudgeVo.getTypeWorkCode());
                                //存入工时表
                                workTimeMapper.insert(workTimeVo);
                                //设置图号编码
                                incomePartJudgeVo.setWorkTimeCode(str);
                            }
                        }
                    }
                    //---------------------------------操作人
                    StringBuffer operator = new StringBuffer();
                    if(!StringUtils.isEmpty(listData.get(assignJobIndex))){
                        if (listData.get(assignJobIndex).trim().contains("、")){
                            String[] splits = listData.get(assignJobIndex).trim().split("、");
                            for (int j = 0; j < splits.length; j++) {
                                String jobNum = iUserDao.selectByFullName(splits[j]);
                                if (j == 0){
                                    operator.append(jobNum);
                                }else {
                                    operator.append("、").append(jobNum);
                                }
                            }
                        }else {
                            operator.append(iUserDao.selectByFullName(listData.get(assignJobIndex).trim()));
                        }
                        //操作人
                        incomePartJudgeVo.setOperator(String.valueOf(operator));
                    }else {
                        //操作人
                        incomePartJudgeVo.setOperator(String.valueOf(operator));
                    }
                    //================================================================
                    //生成工单号 AVIC2020111700001A
                    //1.获取当前日期
                    String currentDate = HexUtil.getCurrentDateYYYYMMDD();
                    String dataStr="%"+currentDate+"%";
                    LinkedHashMap listmap = incomePartJudgeMapper.selectWorkOrderNumber(dataStr);
                    int sum = Integer.valueOf(String.valueOf(listmap.get("number")));
                    String newWorkOrderNumber="";
                    if (sum != 0){//不为空
                        //根据已存在数+1 生成工单号
                        String format = String.format("%05d", sum+1);
                        newWorkOrderNumber = SIGN + currentDate + format + COMPLETE_LIST_SIGN;
                    }else {//为空
                        String format = String.format("%05d", 1);//00001
                        newWorkOrderNumber =  SIGN + currentDate + format + COMPLETE_LIST_SIGN;
                    }
                    incomePartJudgeVo.setWorkOrderNumber(newWorkOrderNumber);
                    //设置新的工单号
                    incomePartJudgeVo.setWorkOrderNumber(newWorkOrderNumber);
                    //================================================================
                    //订单号
                    incomePartJudgeVo.setOrderNumber(listData.get(8));
                    //型号
                    incomePartJudgeVo.setModelNumber(listData.get(modelNumberIndex));
                    //型别
                    incomePartJudgeVo.setModelType(listData.get(modelTypeIndex));
                    //零件名称
                    incomePartJudgeVo.setPartName(listData.get(partNameIndex));
                    //热表序
                    incomePartJudgeVo.setHeatSurfaceSequence(listData.get(heatSurfaceSequenceIndex));
                    //来件数量
                    if (!StringUtils.isEmpty(listData.get(9))) {
                        incomePartJudgeVo.setIncomePartQuantity(listData.get(9));
                    }
                    //外委
                    incomePartJudgeVo.setOutsource(listData.get(10));
                    //来件时间
                    if (!StringUtils.isEmpty(listData.get(11))) {
                        incomePartJudgeVo.setIncomePartTime(listData.get(11));
                    }
                    //紧急程度
                    incomePartJudgeVo.setDegreeUrgency(listData.get(12));
                    //需求时间
                    if (!StringUtils.isEmpty(listData.get(13))) {
                        incomePartJudgeVo.setDemandTime(listData.get(13));
                    }
                    //备注
                    incomePartJudgeVo.setRemark(listData.get(14));
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(15))) {
                        incomePartJudgeVo.setQuantityCompleted(listData.get(15));
                    }
                    //未完成数量
                    if (!StringUtils.isEmpty(listData.get(16))) {
                        incomePartJudgeVo.setUnfinishedQuantity(listData.get(16));
                    }
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(17))) {
                        incomePartJudgeVo.setQuantityCompletedOne(listData.get(17));
                    }
                    //完成时间
                    if (!StringUtils.isEmpty(listData.get(18))) {
                        incomePartJudgeVo.setTimeCompletedOne(listData.get(18));
                    }
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(19))) {
                        incomePartJudgeVo.setQuantityCompletedTwo(listData.get(19));
                    }
                    //完成时间
                    if (!StringUtils.isEmpty(listData.get(20))) {
                        incomePartJudgeVo.setTimeCompletedTwo(listData.get(20));
                    }
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(21))) {
                        incomePartJudgeVo.setQuantityCompletedThree(listData.get(21));
                    }
                    //完成时间
                    if (!StringUtils.isEmpty(listData.get(22))) {
                        incomePartJudgeVo.setTimeCompletedThree(listData.get(22));
                    }
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(23))) {
                        incomePartJudgeVo.setQuantityCompletedFour(listData.get(23));
                    }
                    //完成时间
                    if (!StringUtils.isEmpty(listData.get(24))) {
                        incomePartJudgeVo.setTimeCompletedFour(listData.get(24));
                    }
                    //完成数量
                    if (!StringUtils.isEmpty(listData.get(25))) {
                        incomePartJudgeVo.setQuantityCompletedFive(listData.get(25));
                    }
                    //完成时间
                    if (!StringUtils.isEmpty(listData.get(26))) {
                        incomePartJudgeVo.setTimeCompletedFive(listData.get(26));
                    }
                    //报废数量
                    if (!StringUtils.isEmpty(listData.get(27))) {
                        incomePartJudgeVo.setScrapQuantity(listData.get(27));
                    }
                    //报废单号
                    incomePartJudgeVo.setScrapOrderNumber(listData.get(28));
                    //完成率
                    incomePartJudgeVo.setCompletionRate(listData.get(29));
                    //去向
                    incomePartJudgeVo.setWhereabouts(listData.get(31));
                    //停留时间
                    if (!StringUtils.isEmpty(listData.get(32))) {
                        incomePartJudgeVo.setResidenceTime(listData.get(32));
                    }
                    //来件验收结果
                    incomePartJudgeVo.setIncomePartJudgeResult(listData.get(33));
                    //逻辑删除标识
                    if (incomePartJudgeVo.getIncomePartQuantity().equals(incomePartJudgeVo.getUnfinishedQuantity()) && StringUtils.isEmpty(incomePartJudgeVo.getTimeCompletedOne())
                       && incomePartJudgeVo.getIncomePartJudgeResult().equals(INSPECTION_RESULT)){
                        incomePartJudgeVo.setDeleteFlag("2");
                    }else {
                        incomePartJudgeVo.setDeleteFlag("1");
                    }
                    //检验员
                    incomePartJudgeVo.setInspector(listData.get(34));
                    //创建人
                    User user = iUserDao.selectByPk(idName);
                    incomePartJudgeVo.setCreator(user.getJobNum());
                    Date date = new Date();//获取当前的日期
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
                    String strDate = df.format(date);//获取String类型的时间
                    incomePartJudgeVo.setCreateTime(strDate);
                    incomePartJudgeMapper.importBasicInsert(incomePartJudgeVo);
                    if (TWO.equals(incomePartJudgeVo.getDeleteFlag())){
                        Route route = mainProductionMapper.selectRouteOne();
                        //工单表
                        WorkOrder workOrder = new WorkOrder();
                        workOrder.setWorkOrderNumber(incomePartJudgeVo.getWorkOrderNumber());
                        workOrder.setIncomePartUnitCode(incomePartJudgeVo.getIncomePartUnitCode());
                        workOrder.setModelNumber(incomePartJudgeVo.getModelNumber());
                        workOrder.setModelType(incomePartJudgeVo.getModelType());
                        workOrder.setDrawNoCode(incomePartJudgeVo.getDrawNoCode());
                        workOrder.setPartName(incomePartJudgeVo.getPartName());
                        workOrder.setHeatSurfaceSequence(incomePartJudgeVo.getHeatSurfaceSequence());
                        workOrder.setTypeWorkCode(incomePartJudgeVo.getTypeWorkCode());
                        workOrder.setIncomePartQuantity(incomePartJudgeVo.getIncomePartQuantity());
                        workOrder.setIncomePartTime(incomePartJudgeVo.getIncomePartTime());
                        workOrder.setOrderNumber(incomePartJudgeVo.getOrderNumber());
                        workOrder.setState(ZERO);
                        workOrder.setCurrentLocation(route.getId());
                        workOrder.setCurrentQuantity(incomePartJudgeVo.getIncomePartQuantity());
                        workOrder.setCreator(incomePartJudgeVo.getCreator());
                        workOrder.setCreateTime(incomePartJudgeVo.getCreateTime());
                        mainProductionMapper.insertWorkOrder(workOrder);
                        //在工表
                        WIP wip = new WIP();
                        wip.setWorkOrderNumber(incomePartJudgeVo.getWorkOrderNumber());
                        wip.setState(ZERO);
                        wip.setCurrentLocation(route.getId());
                        wip.setEntryTime(incomePartJudgeVo.getCreateTime());
                        wip.setEntryPerson(incomePartJudgeVo.getCreator());
                        wip.setCurrentQuantity(incomePartJudgeVo.getIncomePartQuantity());
                        mainProductionMapper.insertWIP(wip);
                        //生产实际表
                        OrderResource orderResource = new OrderResource();
                        orderResource.setWorkOrderNumber(incomePartJudgeVo.getWorkOrderNumber());
                        orderResource.setOrderNumber(incomePartJudgeVo.getOrderNumber());
                        orderResource.setEntryTime(incomePartJudgeVo.getCreateTime());
                        orderResource.setEntryPerson(incomePartJudgeVo.getCreator());
                        orderResource.setState(ZERO);
                        orderResource.setRoutePosition(route.getId());
                        orderResource.setCurrentQuantity(incomePartJudgeVo.getIncomePartQuantity());
                        mainProductionMapper.insertOrderResource(orderResource);
                    }

                }
            }
            //删除文件
            DeleteFileUtil.delete(file);
            return ResponseTemplate.builder().code(0).message("导入成功").count(Long.valueOf(count)).data(repeOrderNumber).build();
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }
        finally {
            lock.unlock();
        }
    }

    /**
     *@Description: 来料信息确认按钮
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/18
     */
    @Override
    public ResponseTemplate confirmEntryInfo(String workOrderNumber,String id) {
        try{
            lock.lock();
            //操作人
            User user = iUserDao.selectByPk(id);
            //主表
            int limits =incomePartJudgeMapper.updateDoading(workOrderNumber);
            //工单号表
            WorkOrder workOrder = mainProductionMapper.selectWorkOrderByPk(workOrderNumber);
            workOrder.setCurrentLocation(INCOMEPARTENTRY);
            workOrder.setModifier(user.getJobNum());
            int limit = mainProductionMapper.updateWorkOrder(workOrder);
            //生产在工表
            WIP wip = mainProductionMapper.selectWIPByPk(workOrderNumber);
            wip.setCurrentLocation(INCOMEPARTENTRY);
            int rows =  mainProductionMapper.updateWIP(wip);
            //生产实际表
            String postion = BASICINFORMATIONSOURCE;
            List<OrderResource> orderResourceList = mainProductionMapper.selectOrderResourceByworkOrderNumber(workOrderNumber,postion);
            OrderResource orderResource = orderResourceList.get(0);
            Date date = new Date();//获取当前的日期
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            String strDate = df.format(date);//获取String类型的时间
            //上一状态完成时间
            orderResource.setCompletionTime(strDate);
            //上一状态完成人
            orderResource.setCompletedPerson(user.getJobNum());
            mainProductionMapper.updateOrderResource(orderResource);
            //当前位置
            orderResource.setRoutePosition(INCOMEPARTENTRY);
            //投入时间
            orderResource.setEntryTime(strDate);
            //投入人
            orderResource.setEntryPerson(user.getJobNum());
            //完成时间
            orderResource.setCompletionTime(null);
            //完成人
            orderResource.setCompletedPerson(null);
            int row = mainProductionMapper.insertOrderResource(orderResource);
            if(rows>0 && row >0 &&limit >0 && limits >0) {
                return ResponseTemplate.builder().code(0).message("确认成功").count(1l).build();
            } else {//没有异常并且修改数据失败，原则上不出现
                return ResponseTemplate.builder().code(1).message("确认失败").count(0l).build();
            }
        }catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResponseTemplate.builder().code(1).message(e.getMessage()).count(0l).build();
        }
        finally {
            lock.unlock();
        }
    }
}